[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why is break not syntactically required to be the last statement in a block (anymore)?
- From: Lars Müller <appgurulars@...>
- Date: Wed, 27 Jul 2022 00:01:57 +0200
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:
LuaJIT supports "goto"
yet doesn't allow break as non-last statement in
If you use goto, you might as well use goto to exit the
after a break using a forward goto seems incredibly dirty to
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.