Sujet : Re: goto considered helpful
De : already5chosen (at) *nospam* yahoo.com (Michael S)
Groupes : comp.lang.cDate : 13. Dec 2024, 13:39:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20241213143911.00004af2@yahoo.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
User-Agent : Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)
On Fri, 13 Dec 2024 11:12:13 +0000
bart <
bc@freeuk.com> wrote:
Some people don't like ordinary break either. There you could also
suggest using convoluted logic, or using a function instead But here
'break' would be clearly be simpler and easier.
Agreed.
(I'd like to see a lambda example that is simpler than a two-level
break or even a goto.)
>
It would not be simpler than goto, but a little easier to follow.
Relatively to two-level break, it's more general. Suppose, you have 3
levels of nested loops. Two-level break does not help for breaking
out of innermost loop *into* outermost loop.
The problem with lambda in this role is that it would be an overkill.
Also if one wants simplicity of writing then David's suggestion for
lambda without capture is not sufficient. On the other hand, lambda
with capture of full environment by reference is very easy to write,
but potentially very hard to follow and error-prone.
I am strictly inclined to think that goto is better than all
alternatives proposed so far.
I've had a quick look through my codebases (not C), and I couldn't
see an example of a numbered break. All I could find was the
equivalant of:
break # the vast majority
break all
The latter breaks out of the outermost loop.
For the reason explained above I don't like 'break all' idea.