How to break out of nested loops in Java?

To break out of two or more loops in Java, use break with a label, pointing to the topmost loop.

Here's how you do it:

topmost:
for (int i = 0; i < 100; i++) {
  for (int j = 0; j < 100; j++) {
    for (int l = 0; l < 100; l++) {
      if (i + j + l > 3) {
        break topmost;
      }

      System.out.println(i + " " + j + " " + l);
    }
  }
}

System.out.println("Done!");

// prints:
// 0 0 0
// 0 0 1
// 0 0 2
// 0 0 3
// Done!