I would like to use a for-loop in Lua, but be able to identify what the last iterated value was:
local i
for i=0,10 do
if i==5 then break end
end
print(i) --always prints nil
Is there some way to prevent "i" from being re-declared in the for loop block, instead of shadowing my upvalue of the same name?
Currently, I have to use a while loop to achieve the expected results, which defeats the clarity of the for loop's syntax. Is this just another Lua caveat one has to expect as part of its language quirks?