Comment by ufo

Comment by ufo 14 hours ago

0 replies

That was already the case in previous versions of Lua. You could assign to the loop variable but the assignment would be overwritten in the next loop iteration.

https://www.lua.org/manual/5.3/manual.html#3.3.5

The loop count was fixed at the start of the loop. One of the reasons for this was performance. For loops behave differently if the step count is positive or negative, and it's a bit faster to compute that once, before the loop, than to repeat it every iteration.