Named loops voted into C2y
I thought C++ folk might be interested to learn that WG14 decided last week to add named loops to the next release of C. Assuming that C++ adopts that into C, that therefore means named loops should be on the way for C++ too.
The relevant paper is https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm and to summarise it, this would become possible:
selector:
switch (n) {
for (int i = 0; i < IK; ++ i) {
break selector; // break the switch from a loop!
}
}
loop:
for (int j = 0; j < JK; ++ j) {
switch (n) {
break loop; // break the loop from a switch!
continue loop; // this was valid anyway,
// but now it's symmetrical
}
}
The discussion was not uncontentious at WG14 about this feature. No syntax will please a majority, so I expect many C++ folk won't like this syntax either.
If you feel strongly about it, please write a paper for WG14 proposing something better. If you just vaguely dislike it in general, do bear in mind no solution here is going to please a majority.
In any case, this is a big thing: named loops have been discussed for decades, and now we'll finally have them. Well done WG14!