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
27
u/nadmaximus Feb 27 '26
I've been coding since 1982. The fear of goto is amusing.
12
u/SinisterRectus Feb 26 '26 edited Feb 26 '26
Lua is famously conservative with respect to what is included in the language. A restricted version of goto was added because it gives you the tools to implement a continue or a multiple-loop break. Continue is more specific and non-essential.
See also https://www.luafaq.org/#T1.26 and http://lua-users.org/wiki/ContinueProposal
14
u/ibisum Feb 27 '26
4
u/vga256 Feb 27 '26
First hit on a ddg search: why does lua not have continue
6
u/Old_County5271 Feb 27 '26
Lua developers usually give the excuse of minimalism, but if they wanted minimalism, why offer pairs? next, state, nil does the exact same thing and is much clearer, why offer os.execute when you can io.popen"cmd":close()? Why is there a string.gmatch when string.match accepts a positional parameter? they mention that function a:b is syntax sugar for a.b(self), If syntax sugar is easy to implement, then why not have assignments inside conditionals, continue, += ,etc?
who knows really.
3
u/smtp_pro Feb 26 '26
Honestly it makes me rethink how to accomplish what I want to do and tends to result in easier to understand code. You don't really need it.
Basically anywhere I would use it I can usually replace it with a conditional function. Like instead of
I could have something like
Or maybe I factor it out into a function with an early return like:
2
u/Bedu009 Feb 26 '26
It has goto
1
u/sitrucz Feb 27 '26
You can wrap in repeat until true and use break. Go to seems to be the standard though.
1
u/markand67 Feb 27 '26
People kept complaining about lack of continue so they added goto instead ¯\(ツ)/¯
1
u/Zansin777 Feb 27 '26
If you're not hard stuck in only using Lua, consider using Luau instead. It's Roblox version of Lua but with continue, type checking and faster interpreter.
1
u/Bright-Historian-216 Feb 27 '26
right, but some flavors of lua don't have goto either. so we have to just suck it up ;-;
1
u/Koala_eiO Aug 11 '26
Because Lua lacks the most basic features of a programming language. Not having exceptions is a crime. Trying to access
a.b.c.dwithout being able to throw an exception makes what should be one line into a monstruous if.1
u/TheGameTheorys55 Aug 26 '26
1
u/cripsyinmlik Feb 27 '26
Mechanism > Policy. GOTO ::label:: can provide the same mechanics as continue.
1
u/smog_alado Feb 27 '26
One argument I've heard from the Lua team is that continue is rarely used.
0
u/perthecther Feb 28 '26
Just use LuaU it has so much more language features and is way more performant than native lua however you lose a lot of the ecosystem
2
u/[deleted] Feb 27 '26
[removed] — view removed comment
0
u/[deleted] Feb 26 '26
[deleted] — view deleted comment