/ ; :
, 1, , for i = start , end , step do … end, for i = 1, 10, 3 do … for i = 10, 1, -1 do …. , .
"" while -loops , , . :
local diff = 0
for i = 1, n do
i = i+diff
if i > n then break end
-- code here
-- and to change i for the next round, do something like
if some_condition then
diff = diff + 1 -- skip 1 forward
end
end
That way you can't forget the increment i, and you still have the adjusted ione available in your code. Deltas are also stored in a separate variable, so checking for errors is quite simple. ( iauto-increments should work, any assignment ibelow the first line of the loop body is an error, check if you are assigned diff, check the branches, ...)
source
share