Cycle counter reduction as the cycle progresses

I am trying to decrease the for loop counter when starting a loop. Unfortunately, Lua does not seem to allow this. This piece of code should work forever:

for i = 1, 100 do
    print (i)
    i = i - 1
end

but actually it just prints a series of 1-100. Is it for design? If so, how to reduce the duty cycle counter (for example, because the current cycle has been disqualified and must be run again)?

+4
source share
1 answer

This is by design. From the Lua Reference Guide :

3.3.5 - for the operator

All three control expressions are evaluated only once before the cycle begins. All of them must lead to numbers.

, i .

+3

All Articles