I\'ve got a nested loop construct like this:
for (Type type : types) {
for (Type t : types2) {
if (some condition) {
// Do somethin
Labeled break concept is used to break out nested loops in java, by using labeled break you can break nesting of loops at any position. Example 1:
loop1:
for(int i= 0; i<6; i++){
for(int j=0; j<5; j++){
if(i==3)
break loop1;
}
}
suppose there are 3 loops and you want to terminate the loop3: Example 2:
loop3:
for(int i= 0; i<6; i++){
loop2:
for(int k= 0; k<6; k++){
loop1:
for(int j=0; j<5; j++){
if(i==3)
break loop3;
}
}
}