If you write the label on break, it's
public class Test {
public static void main(String[] args) {
outerloop:
for (int i=0; i < 5; i++) {
for (int j=0; j < 5; j++) {
if (i * j > 6) {
System.out.println("Breaking");
break outerloop;
}
System.out.println(i + " " + j);
}
}
System.out.println("Done");
}
}
Specify the label outerloop: before the conditional statementWest When break outerloop; is encountered, it leaves the repeat statement where the label starts. In the code above,
outerloop:
for (int i=0; i < 5; i++) {
for (int j=0; j < 5; j++) {
if (i * j > 6) {
System.out.println("Breaking");
break outerloop;
}
System.out.println(i + " " + j);
}
This iteration statement where outerloop started ends
System.out.println("Done");
This is going to work.
© 2024 OneMinuteCode. All rights reserved.