Skip to content
Justice Tech School

break, continue and Labels

break leaves a loop, continue skips a round and a label exits nested loops.

Example
public class Main {
  public static void main(String[] args) {
    outer:
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (j == 1) continue;
        if (i == 2) break outer;
        System.out.println(i + "," + j);
      }
    }
  }
}

Result

0,0
0,2
1,0
1,2

Exercise

Skip a round.

;

Quiz Test

What does break outer do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.