Java continue statement

In Java, continue skips the rest of the current loop iteration. Execution moves to the loop update or condition check.

A simple example

Skip just the number 2

  1. Start with Visit 1 through 3
  2. Do this Skip 2
  3. Result 1 → 3
Skipping one number still allows the next number to be printed.
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        for (int n = 1; n <= 3; n++) {
            if (n == 2) {
                continue;
            }
            System.out.println(n);
        }
    }
}
Output
1
3
Valid intervals: 0, 4, 6. Intervals counted: 3. Total visitors: 10.
Count the quiet interval too

A counter records visitors in each time interval. A negative reading signals a fault, while zero means the counter worked and nobody entered. Keeping 0, 4 and 6 gives three valid intervals and ten visitors.

  • Continue Statement
  • Labeled Continue Statement