C++ Logo

std-proposals

Advanced search

Re: [std-proposals] !continue

From: connor horman <chorman64_at_[hidden]>
Date: Thu, 9 Nov 2023 09:12:54 -0500
Adding to colors to paint the bikeshed, what about `continue expr;`?

`expr` would be limited to either `literal-expression` or a parenthesized
expression (any expression inside the parentheses) to avoid ambiguity
between an id-expr and a label. If `expr` - contextually converted to
`bool` - evaluates to true, then the post-iterative step is evaluated. If
it evaluates to false, then it is not evaluated. `continue;` and `continue
label;` would default to `continue true;`. The syntax order for having both
a label and an expr is `continue label expr;`. The program is ill-formed if
this syntax form is used to break a loop other than a for loop, and if used
in a ranged for loop to skip the expr, the behaviour is undefined unless
the iterator-type for the range expression models *ForwardIterator*.

On Thu, 9 Nov 2023 at 07:24, Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Tue, Nov 7, 2023 at 12:14 PM sasho648 wrote:
> >
> > Anyone mentioned goto? - With goto you can do exactly what the OP is
> asking for:
> >
> > for ( ; SerialSimGsm.available(); ++p )
> > rev_con:
> > {
> > if ( p >= &buf[sizeof(buf) - 1u] ) break;
> > p[0u] = SerialSimGsm.read();
> > p[1u] = '\0';
> > unsigned const len = std::strlen(buf);
> > char *ending = nullptr;
> > if ( nullptr != (ending = std::strstr(buf, "\r\n")) )
> > {
> > ending[0u] = '\0';
> > ending[1u] = '\0'; // Overwrite the "\r\n" with
> "\0\0"
> > if ( ending != buf ) this->ProcessInput();
> > buf[0u] = '\0';
> > p = buf;
> > goto rev_con; // Don't allow 'p' to be incremented
> > }
> > }
>
>
>
> Your strategy causes an assertion failure in my code:
>
> https://godbolt.org/z/v6Px1Tao4
>
> because your 'goto' is skipping the pre-iterative condition check.
>
> Perhaps there should be four ways of continuing a loop:
>
> continue; // Don't skip anything
> continue(skip post); // Skip the post-iterative step
> continue(skip pre); // Skip the pre-iterative condition
> check
> continue(skip both); // Skip both the post-iterative
> step and the pre-iterative condition check
>
> The four words 'skip, pre, post, both' would not be keywords in the
> C++ language, but would be words with special meaning only when
> encountered in parentheses following 'continue'.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-11-09 14:13:10