C++ Logo

std-proposals

Advanced search

Labeled 'continue' and 'break'

From: Ryan Nicholl <rnicholl_at_[hidden]>
Date: Wed, 11 Mar 2020 00:11:54 +0000
I'd like to suggest adopting labeled break and continue statements,

e.g.

label1: for( int x = 0; x < 5; x++)
{
label2: for (int y = 0; y < 5; y++)
{
for (int z = 0; z < 5; z++)
{
std::cout << x << ',' << y << ',' << z << std::endl;
if (z+y == 8) continue label2;
if (z+x == 3) break label2;
if (x + y + z == 13) break label1;
}
}
}

Other languages have it, and it's convenient with nested loops.

Received on 2020-03-10 19:14:49