C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Discussion: A proposed repeat statement for C++

From: A Johnston <ajohnston54637_at_[hidden]>
Date: Tue, 17 Nov 2026 08:32:57 -0700
Hello all,

I have done written a lot of real time code without ever using the goto
keyword. Here are some examples of scoping control flow using a while loop.
The second version gives you multi level jumps and control over which
variables are in scope.

```
    int x = 0;
    for (int i = 0; i < 5; i++) {
        while (true) {
            x++;
            printf("Hello\n");

            if (x != 2)
                continue;

            break;
        }
    }
```

```
    int x = 0;
    for (int i = 0; i < 5; i++) {
        while ([&] {
            x++;
            printf("Hello\n");

            if (x != 2)
                return true;

            return false;
        }()) {
        }
    }
```
All the best,

Adrian

Received on 2026-11-17 15:33:24