/*
* A:break的使用场景
* 只能在switch和循环中
*/
class Demo1_Break {
public static void main(String[] args) {
/*outer:for(int y = 1;y<=5;y++){
if(y==3) break;
for (int x = 1;x <= 10 ;x++ ) {
if (y==2&&x == 4) {
break outer; //跳出循环
}
System.out.println("x = " + x);
}
System.out.println("***********************************");
}
System.out.println("-------------------------");
}*/
/*for (int x = 1;x <= 10 ;x++ ) {
if (x == 4) {
break break; //跳出循环
}
System.out.println("x = " + x);
}*/
/*for(int y = 1;y<=5;y++){
if(y==3) break;
for (int x = 1;x <= 10 ;x++ ) {
if (x == 4) {
break; //跳出循环
}
System.out.println("x = " + x);
}
System.out.println("***********************************");
}
System.out.println("-------------------------");
}*/
outer:for(int y = 1;y<=5;y++){
if(y==3) break;
for (int x = 1;x <= 10 ;x++ ) {
if (x == 4) {
break outer; //跳出循环
}
System.out.println("x = " + x);
}
System.out.println("***********************************");
}
System.out.println("-------------------------");
}
}
|
|