C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Labeled 'continue' and 'break'
From: jianping z (zjpwork_at_[hidden])
Date: 2020-03-11 20:38:07


I think it would look much better with label being added inside for(label: ...) for continue/break

for ( label1: int x = 0; x < 5; x++)
{
  for ( label2: 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;
    }
  }
}

and it would work for "while(label: ...) {}", "do {} while(label: ...)" as well.

how do you think?

Thanks

On 3/10/2020 06:11 PM, Ryan Nicholl via Std-Proposals wrote:

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.



STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups