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
6
u/MindScape00 Feb 27 '26
One factor against this is simplifying code readability by reducing indentation and the depth of if then statements, which can actually make code harder to follow.
A continue statement would simplify this in the same way a return does for allowing early exit out of a block. I.e., early exit if an arg is missing in a function call can be done also as a general
if x then (work here) end, but common practice is more soif not x then return endbefore going to the work. Which is usually better for simplifying the formatting & easier to follow. But we can't do this in a loop for continue, which is unfortunate. That said there IS tricks to do this using a repeat until true wrapper so that we can just break out of that iteration as a form of continue, but that is more annoying and makes code harder to follow.