lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Interesting hypothesis. Second thought: Forward gotos would also allow skipping a "return" (which exits a function), so why should it be treated differently than "break" (which exits a loop)? If the following code wasn't syntactically invalid due to "return" being a retstat and thus only allowed at the end of a block, it would print "yay":

(function() goto forward return ::forward:: print"yay" end)()

On 26.07.22 22:36, Ryan Starrett wrote:


On Tue, Jul 26, 2022 at 4:09 PM Lars Müller <appgurulars@gmx.de> wrote:
LuaJIT supports "goto" yet doesn't allow break as non-last statement in
a block.

If you use goto, you might as well use goto to exit the loop. Jumping
after a break using a forward goto seems incredibly dirty to me...

On 26.07.22 15:27, Paul Ducklin wrote:
>
> >Why should "break" statements be allowed before the end of a block?
>
> Forward goto?
>
> I don’t think I have ever used goto in Lua but it’s there for those
> who want it (but was not in 5.1). Maybe that’s the reason for the
> grammar change?
>
Here is my hypothesis until (or if) an official response is given. Break is semantically equivalent to "goto break", and it'd be silly to legislate the usage of labels like this. The parser only sees break statements as labels.