Yeah that's fair - didn't think this through - well just don't use for then.On Thu, Nov 9, 2023 at 2:24 PM Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org> 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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals