我有以下 for 循环:
for (int i = 0; i<arr.length;i++) {
for(int j =0; j<someArr.length; j++) {
//after this inner loop, continue with the other loop
}
}
我想跳出内循环并继续外循环的迭代。我该怎么做?
最佳答案
通常你可以使用lable
和break
的组合来跳转到你想要的地方,如下所示
OUTER_LOOP: for (int i = 0; i<arr.length;i++) {
for(int j =0; j<someArr.length; j++) {
//after this inner loop, continue with the other loop
break OUTER_LOOP;
}
}
如果您想像这样中断到外循环中的某个位置,请将标签放在您想要跳转到的位置(当前循环之外)并使用该标签 在break 语句中。
for (int i = 0; i<arr.length;i++) {
//line code 1
OUTER_LOOP: // line code 2
for(int j =0; j<someArr.length; j++) {
//after this inner loop, continue with the other loop
break OUTER_LOOP;
}
}
关于java - 嵌套循环继续java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52013404/