codegurukool.com · Free coding tutorials & online compiler

Home › Java Tutorial › Java break and continue

Java break and continue

Control a loop from inside.

break leaves the loop completely. continue skips the rest of the current round and goes to the next one.

Example code

public class Main {
  public static void main(String[] args) {
    for (int i = 1; i <= 5; i++) {
      if (i == 2) continue;
      if (i == 4) break;
      System.out.println(i);
    }
  }
}

Run this code in the online editor

← Java for loopJava arrays →