如何突破Java中的嵌套循环? - How do I break out of nested loops in Java?

问题:

I've got a nested loop construct like this: 我有一个像这样的嵌套循环构造: app

for (Type type : types) {
    for (Type t : types2) {
         if (some condition) {
             // Do something and break...
             break; // Breaks out of the inner loop
         }
    }
}

Now how can I break out of both loops? 如今如何摆脱两个循环? I've looked at similar questions, but none concerns Java specifically. 我看过相似的问题,但没有一个是Java特有的。 I couldn't apply these solutions because most used gotos. 我没法应用这些解决方案,由于大多数使用的gotos。 oop

I don't want to put the inner loop in a different method. 我不想将内部循环使用其余方法。 this

I don't want to rerun the loops. 我不想从新运行循环。 When breaking I'm finished with the execution of the loop block. 中断时,我完成了循环块的执行。 spa


解决方案:

参考一: https://stackoom.com/question/3ijj/如何突破Java中的嵌套循环
参考二: https://oldbug.net/q/3ijj/How-do-I-break-out-of-nested-loops-in-Java
相关文章
相关标签/搜索