r/lua • u/DrSergei • Feb 26 '26
Help Why is there NO "continue" in Lua?
I was stunlocked to find out that there is no "continue" instruction for loops in Lua. Why is that? It seems so natural to have it.
I saw some scripts where goto is used for mimicking continue statements, but It's honestly not the so;ution I would comfortably accept...
26
Upvotes
View all comments
Show parent comment
4
u/didntplaymysummercar Feb 27 '26
For
continuethey also gave the explanation of it being ambiguous if it'll skip the inner or outer loop. Why not make it work likebreakalready does or likecontinueworks in C, Pascal, C++, JavaScript, Java, C#, Bash, Python... who knows 🤷It's one of the baffling Lua choices, another one is how tables and arrays are the same type - cute and "simple" at first but due to it each table indexing (both read and write) has extra code for the heuristic, table struct is bigger, and people keep running into problems with length (how it's computed changed in 5.5 too) and iteration due to nils stored in arrays. There's also no way to get element count of the table or check if the array part is being used or force its use (other than at table creation) it forbid it. Yet another is making the loop iterator immutable in 5.5, something no language other than Rust does and there it's part of the immutability by default, not a special case.
Some of these quirks is the kind of stuff PHP gets hated for, yet people here will claim Lua is a better language than Python, and people elsewhere will focus on silly superficial things like inequality operator not being
!=(admittedly it'd be cool if they added an alternate operator, like Python 2 had), lack of curly braces or 1 based indexing.