Some time ago I made a simple system used for stacking items which are of "charged" type. Everything went fine when I made it in GUI. A few days ago I decided to make the same thing in JASS. However there is a problem. My system loops through unit's inventory to check if there are two charged items with the same id. As I said it works in GUI. But my JASS function doesn't work every time. It stops when first slot of inventory is occupied by item of not charged type, otherwise it works. It seems as when if/else in the loop returns false, the whole loop returns false as well and ends (also see comments in the code).
"The same" thing in JASS

JASS:
function StackConditions takes nothing returns boolean
return GetItemType(GetManipulatedItem()) == ITEM_TYPE_CHARGED
endfunction
function StackActions takes nothing returns nothing
local unit u
local integer ia
local integer ib
local item i1
local integer itemid1
local item i2
local integer itemid2
set u = GetManipulatingUnit()
set ia = 0
set ib = 0
loop
exitwhen ia > 5
set i1 = UnitItemInSlot(u, ia)
set itemid1 = GetItemTypeId(i1)
loop
exitwhen ib > 5
set i2 = UnitItemInSlot(u, ib)
set itemid2 = GetItemTypeId(i2)
if (((itemid1 == itemid2) and (ia != ib)) and ((GetItemType(i1) == ITEM_TYPE_CHARGED) and (GetItemType(i2) == ITEM_TYPE_CHARGED))==true) then
call SetItemCharges(i1, GetItemCharges(i1)+GetItemCharges(i2))
call RemoveItem(i2)
else
endif
set ib = ib + 1
endloop
set ia = ia + 1
endloop
set u = null
set i1 = null
set i2 = null
endfunction
function InitTrig_Stack takes nothing returns nothing
set gg_trg_Stack = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Stack, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( gg_trg_Stack, Condition( function StackConditions ) )
call TriggerAddAction( gg_trg_Stack, function StackActions )
endfunction
What can be causing such a problem?
Oh, and hi everyone by the way...