The following example piston shows that there is some unexpected behavior with the special $index
variable used by default in for loops. The output shows that for the zero index, the $index
variable does not access the element in the array correctly:
+244ms âletters[0]: A letters[index]: A
+319ms â$index: 0 index: 0 letters[$index]: letters[index]: A
+394ms â$index: 1 index: 1 letters[$index]: B letters[index]: B
+466ms â$index: 2 index: 2 letters[$index]: C letters[index]: C
Instead, letters[$index]
is null. Since both assigning $index
to index
and constructing the loop to use index
as the counter variable work fine to access the zero index this seems like it might be a parsing or coercion issue. The easy workaround is to use a custom integer counter variable.