C++ Logo

std-proposals

Advanced search

Re: More flexible break statements.

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 16 Aug 2019 19:51:14 -0400
On Fri, Aug 16, 2019 at 7:43 PM Walt Karas via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Another option would be to redefine 'break' as a void-returning
> expression, so that:
>
> do { /* yada */ } while (0);
>
> could become:
>
> for ( ; ; break) { /* yada */ }
>
> It's more readable if you know a loop isn't really a loop from the
> beginning.
>

Once you're making up new meanings for control-flow keywords, what would be
wrong with

    {
        /* yada */
        if (something) goto bottom;
        /* yada */
    }
    bottom:;

or

    []() {
        /* yada */
        if (something) return;
        /* yada */
    }();

? C++ already has plenty of ways to spell "goto this place" and/or "break
out of this level of nesting"; I don't think we need more.

"goto case" and "goto default", on the other hand, should probably Just
Work. Try to get buy-in from a compiler vendor. I wouldn't want to waste
paper verbiage on them before showing that they can be useful in practice.

my $.02,
–Arthur

Received on 2019-08-16 18:53:46