Relatedly there is also a proposal active

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2806r1.html

 

introducing scoped do expressions with a specific do return to leave their scope.

 

 

Example from the paper:

 

auto a = do {     if (cond) {         do return 1;     } else {         do return 2;     } };   This would give another option for escaping nested scopes.


 

-----Ursprüngliche Nachricht-----
Von: Sebastian Wittmeier <wittmeier@projectalpha.org>
Gesendet: Mo 01.05.2023 16:10
Betreff: AW: [std-proposals] escaping nested scopes : __escape
An: std-proposals@lists.isocpp.org;

You can use a lambda at the appropriate position instead.

 

[&] {

    for (int i = 0; i < x: i++) {

        for (int j = 0; j < y; j++) {

            for (int k = 0; k < z; k++) {

                if (something)

                    return;

            }

       }

   }

}();