lua-users home
lua-l archive

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


On 28/07/2022 21:17, Lars Müller wrote:
To throw an alternative syntax in the pot: Labeling loops / blocks. This
is how you can continue / exit outer loops in languages like Go or Java:
Loops can be labeled with "<name>: <loop>" and continue/break take an
optional name:

foo: for ... do
    while ... do
        continue foo
    end
end

bar: for ... do
    repeat
        break bar
    until ...
end



These are nice, and I would welcome it even for do...end blocks if they could be made to blend well in the language syntax.

However, they are a sort of absolute jump. I still think the "jump out of the innermost two level" relative behavior may be useful and more localized.

You objected in another messages that it would mess things up if someone added/removed a nesting level. I argue that that it depends on the specific algorithm. Modifying the nesting level could mess things up also for labeled loops/ goto+labels *if* the semantics of the bail-out is relative and not absolute and label positions are not adjusted accordingly.

There will be algorithms where adding a nesting level won't mess things up just because, say, "break 2" does the right thing regardless of the nesting level, whereas with "goto loop2/ break loop2" you could have to move the label around.

Is it worth adding it to the language? Meh! Probably yes if someone could show (with some hard data) that this "relative bail out" semantics is frequently needed. Otherwise it would be just cruft.