Start Coding Now

Break Statement in Java - Exiting Loops

Learn how to use the break statement to exit loops and switch statements prematurely.

Break Statement

The break statement is used to jump out of a loop or a switch statement.

for (int i = 0; i < 10; i++) {
  if (i == 4) {
    break; // Stops the loop when i is 4
  }
  System.out.println(i);
}

Frequently Asked Questions