0
Read the description(C++)
Let's say I have a for loop: for(i=0; i<5; i++) In the for loop I have a while loop: while(condition == true) How can I break ONLY from the while loop?
3 Answers
+ 1
Look at this:
It only breaks the while loop. The break statement always just applies to the most inner loop, where it was called.
int j;
for(int i=0; i<10; i++){
cout<<i<<endl;
j=5;
while(j>0){
cout<<" j: "<<j<<endl;
if(j==2){
break;
}
j--;
}
}
0
Put the break statement in the while loop
0
Thanks alot!
I thought it break from the biggest loop...