lua-users home
lua-l archive

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

On 28/07/2022 17:15, Egor Skriptunoff wrote:
On Thu, Jul 28, 2022 at 5:49 PM Lorenzo Donati wrote:

I would welcome a syntax like "break 4", to exit four loop levels.

Should the following statements also be valid?

break 0x4

break 3+1  -- arithmetic expression calculable at compile time

local level <const> = 3
break level+1  -- arithmetic expression with <constants> in it

That smells like computed goto, and don't see the need for that.
FWIW any syntax that allowed to specify a level would be good.
To avoid issues with what you mention, in order to just specify a "static" level, also something like this:


break ::4::


break @4

or whatever other syntax that is easily parseable with no excessive lookahead and no ambiguities or weird interaction with current language features.

Don't get me wrong, I love Lua has introduced "goto", but it is an advanced features and using it excessively *do* lead to spaghetti code. I don't like the fact that goto was meant to emulate features that in a structured language should be reflected by (well established) control structures (e.g. multilevel break/continue).