I have a program similar to this:
switch(x)
{ case 1:
for(i=0; i<10; i++)
{
if ((i==3) || (i==4) || (i==5) || (i==6) || (i==7))
{
if (foobar[i])
break; // i am talking about this break
}
}
...further program
break; /not this break
if foobar[i]
is true, would the program break out of the case
label or the for
loop?
The break
follows a LIFO type nature, that is, the last break
will come out of the first control structure. So, the break
that you chose would break out of the for-loop, not the case
.
The for
loop.
Please see: break
Statement (C++):
The break statement ends execution of the nearest enclosing loop or conditional statement in which it appears. Control passes to the statement that follows the ended statement, if any.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With