This isn't a specific problem that I actually am trying to implement, but it ocurred to me that I do not know how to do this, so I will give a simple example to illustrate:
Suppose we have a while
loop containing a switch
statement, for instance:
while(some_cond){
switch(some_var){
case 1:
foo();
break;
case 2:
bar();
break;
}
}
what would we do if we wanted to break
out of the while loop in case 1
, say?
We can't do break; break;
, since the second will never happen.
We also can't do break
*un*conditionally in the while
loop, since this would happen in any case
.
Do we have no choice but to if (some_var == 1) break;
in the while
loop, or else append && !flag)
to the while
condition, and set flag = 1
?