Breaking out of a FOR loop causes one last increment of the variable used
-
u = 0 for u = 0 to 5 loop if u == 2 then break endIf repeat print( u ) update() sleep(10) -- prints 3 when it should still be 2 --
This code allows the variable that is used by the FOR loop to be kept once outside of it for means of other uses. In other languages, doing this would retain the variable at the value last assigned to it before it broke out of the loop. With FUZE, it breaks out, but then increments the variable by one. This is unfortunately causing a bit of issue with my coding.
-
Thank you Stew this is super valuable.
-
Just in case it's not obvious to anyone reading this, the workaround is to decrement the variable before exiting the loop so it becomes this:
u = 0 for u = 0 to 5 loop if u == 2 then u -= 1 break endIf repeat print( u ) update() sleep(10)
-
@Martin That's fine until it is fixed and breaks again!
-
Yep, so obviously it's a temporary workaround
-
I believe this was fixed in this most recent patch. Yay!