Is there a universal way to get out of a multi-level loop in java? Or is it necessary to make a competent condition for each level? For example:

for( ... ){ while( ... ){ ... break(2); // не обращайте внимания } } 

I think you understood what I mean.

    1 answer 1

    If I understand you correctly, the label will help you.

     public class Test { public static void main(String[] args) { outerloop: for (int i=0; i < 5; i++) { for (int j=0; j < 5; j++) { if (i * j > 6) { System.out.println("Breaking"); break outerloop; } System.out.println(i + " " + j); } } System.out.println("Done"); } } 

     0 0 0 1 0 2 0 3 0 4 1 0 1 1 1 2 1 3 1 4 2 0 2 1 2 2 2 3 Breaking Done