How do I break out of nested loops in Java?

前端 未结 30 2803
梦毁少年i
梦毁少年i 2020-11-21 11:51

I\'ve got a nested loop construct like this:

for (Type type : types) {
    for (Type t : types2) {
         if (some condition) {
             // Do somethin         


        
30条回答
  •  情深已故
    2020-11-21 11:59

    Use Labels.

    INNER:for(int j = 0; j < numbers.length; j++) {
        System.out.println("Even number: " + i + ", break  from INNER label");
        break INNER;
    }
    

    Refer to this article

提交回复
热议问题