跳出双重for循环。正常使用break的话只能跳出内层循环,想跳出多重循环可通过label跳出.
sca:for (int i = 0; i < 10; i++) { //大循环
System.out.println("i = " + i);
labe:for (int j = i; j < 10; j++) { //中循环
System.out.println("j = " + j);
for (int k = 0; k < 10; k ++) { //小循环
System.out.println("k = " + k);
if (j + k == 5) {
break; //跳出小循环
//break labe; //跳出中循环
//break sca; //跳出大循环
}
}
}
}
网友评论