+ 11
If there was a jump statement "break" inside a nested loop for and it was inside the second for...
will the compiler pass out from the both loops ??
3 ответов
+ 4
no. break stops the last loop that started. loop 1 started then loop 2 and then the break. if the break is inside loop 2 loop 1 will continue.
+ 27
If you need to break the outer loop from inner loop, you can use label like this: http://stackoverflow.com/questions/886955/breaking-out-of-nested-loops-in-java
+ 4
if u can give code example it will help to get the full picture.
Any how I believe this is wht u asking.
for(){ //#1
break; //#b1
for(){ //#2
break;. //#b2
}
}
if #b2 break execute it will break only the #2 for loop and #1 will not break.
if #b1 break it break the #1 for loop and it wouldn't not go to next line so #2 for loop will not execute.
Simply break statement only break the loop it is belongs to.