C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Bringing break/continue with label to C++

From: Chris Ryan <chrisr98008_at_[hidden]>
Date: Wed, 18 Dec 2024 15:03:32 -0800
I disagree with the whole concept of break/continue to a label.

When I was much less experienced, I had to deal with ugly nested
looping/conditional code, like this, where nesting levels incorrectly
interacted with each other. The real issue is poor nested logic, too much
nesting. Maybe some of the inner scope should be broken out to another
function (for isolation).

IMHO, this violates the idea of scope encapsulation. The inner loop/scope
should not know or care what the outer loop/scope is doing nor why. And
vise-versa. Just because you can does not mean you should.

This feature does not do what 'break' or 'continue' should be doing:
'Break' breaks out of the scope and goes to after the _end_ of this scope.
'Continue' stays in the loop, continuing with for the next iteration of the
scope, from the the _top_ of this scope.
We already have a feature that goes to a label (forward or back), it is
called 'goto' and it is mostly discouraged.

I understand the request but I will vote 'No" on this.
We should not be adding any feature, to C or C++, that encourages more
complexity (spaghetti, ugly code-flow side-effects).

Sorry, Not sorry.

On Wed, Dec 18, 2024 at 4:10 PM Jens Maurer via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>>
>> On 18/12/2024 11.49, Jan Schultke via Std-Proposals wrote:
>> > I want to have break/continue statements with labels in C++. Now is the
>> time.
>> >
>> > https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm has been
>> > accepted into C2y, with the syntax:
>> >
>> > label: for (/* ... */) {
>> > while (true) { break label; }
>> > }
>> >
>> > https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3377.pdf proposes to
>> > update this syntax to
>> >
>> > for label (/* ... */) {
>> > while (true) { break label; }
>> > }
>> >
>> > While N3377 may be a bit more syntactically sound (not reusing labels
>> > that are otherwise only goto targets, I'm not a fan of that idea.
>>
>

Received on 2024-12-18 23:03:43