C++ Logo

std-proposals

Advanced search

Re: [std-proposals] !continue

From: Bjorn Reese <breese_at_[hidden]>
Date: Mon, 6 Nov 2023 18:37:09 +0100
On 11/6/23 00:25, Frederick Virchanza Gotham via Std-Proposals wrote:

> Bjorn wrote:
>> The usual solution is to move the increment into the loop
>>
>> while (Serial.available()) {
>> // Do stuff
>> if (condition) {
>> // Do conditional stuff
>> p = buf;
>> } else {
>> ++p;
>> }
>> }
>
>
> Again here you're losing the simplicity of having 'continue' in other
> places in the loop (if the loop were bigger and more complex).

The following minor refactoring is very close to what you ask,
without introducing new language features:

   while (Serial.available()) {
     // Do stuff
     if (condition) {
        // Do conditional stuff
        p = buf;
        continue;
     }
     ++p;
   }

Received on 2023-11-06 17:37:13