traverse order of ForEach
Posted: Fri May 12, 2017 1:35 am
I wonder if this is a bug or intentional ?
Program is:
output is:
While For and ForEachI start with first element in table and stop with last one, ForEach however starts with second element, traverses to last one, and then as last action performs user function on the first element of the table.
Thus one cannot use ForEach if the order of execution is important !
Program is:
Code: Select all
lov={1,2,3,4,5}
For Local i=0 To ListItems(lov)-1
DebugPrint("lov[" .. i .. "]=" .. lov[i])
Next
DebugPrint("-------------")
ForEachI(lov,Function(p_index,p_value) DebugPrint("lov[" .. p_index .. "]=" .. p_value) EndFunction)
DebugPrint("-------------")
ForEach(lov,Function(p_index,p_value) DebugPrint("lov[" .. p_index .. "]=" .. p_value) EndFunction)
Code: Select all
lov[0]=1
lov[1]=2
lov[2]=3
lov[3]=4
lov[4]=5
-------------
lov[0]=1
lov[1]=2
lov[2]=3
lov[3]=4
lov[4]=5
-------------
lov[1]=2
lov[2]=3
lov[3]=4
lov[4]=5
lov[0]=1
Thus one cannot use ForEach if the order of execution is important !