[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: Lorenzo Donati <lorenzodonatibz@...>
- Date: Fri, 29 Jul 2022 16:48:27 +0200
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
foo: for ... do
while ... do
bar: for ... do
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
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
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.