Forum Discussion

EnTerr's avatar
EnTerr
Roku Guru
11 years ago

Checking if FOR was EXIT-ed

I have a FOR loop, which i may EXIT or not - and further after that i need to know if it finished prematurely or by exhausting the range. In example, i came up with this:
for i = stack.count()-1 to 0 step -1:
if stack[i] = myVal then exit for
end for
if i < 0 then ... 'not found

By reading the manual, it seems to confirm my expectations: "When program flow reaches the END FOR statement, the counter is incremented by the amount specified in the STEP increment" - that is, it will increment once more after the last value before exiting, so i should be good by checking if out of bound.

The reason i have any doubt is - in other languages (maybe even BASIC) i remember spec saying something akin to "value of iterator i is undefined after exiting the for loop". So someone knowing the matter (RokuMarkN?), can you relieve my anxiety by saying if my code assumption is good?
No RepliesBe the first to reply