- When break does not have a label, the current loop will be interrupted by default. When a label is specified, it will interrupt the specified label loop
public static void main(String[] args) {
int m=0;
a:for (int i = 0; i < 10; i++) {
System.out.println("iiiiiiiiiiiii");
b:for (int j = 0; j < 10; j++) {
System.out.println("jjjjjj");
if(j==2){
m++;
System.out.println(m);
break a;//打断a的循环
}
}
}
}
- continue jump to the corresponding loop body to continue the loop
public static void main(String[] args) {
int m=0;
a:for (int i = 0; i < 10; i++) {
System.out.println("iiiiiiiiiiiii");
b:for (int j = 0; j < 10; j++) {
System.out.println("jjjjjj");
if(j==2){
m++;
System.out.println(m);
continue a;//打断b的循环,继续a循环
}
}
}
}
- Break interrupts the current loop by default, and continue continues to loop the current loop body by default