char a;
outer:
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
a = (char)System.in.read();
System.in.read(); //再讀一個換行符
System.in.read(); //再讀一個回車符
if(a=='b'){
break outer;
}
if(a == 'c'){
continue outer;
}
System.out.println("內部循環中!");
}
System.out.println("外部循環中!");
}
char a;
outer:
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
a = (char)System.in.read();
System.in.read(); //再讀一個換行符
System.in.read(); //再讀一個回車符
if(a=='b'){
break outer;
}
if(a == 'c'){
continue outer;
}
System.out.println("內部循環中!");
}
System.out.println("外部循環中!");
}
break outer 就是跳出所有的循環.
contiue outer 就是接著執行下一個outer循環
摘自 張仁陽專欄