Operators ·
‹ Previous Next ›
⏱ 5 min read Modified: 2026-07-12

Java continue Statement

The continue statement in Java ends the current iteration of a loop early: the remaining statements in the loop body are skipped, and control moves on to the next iteration. The loop itself keeps running — unlike with the break statement, which terminates the loop entirely.

How continue Works in for, while, and do-while

In while and do-while loops, the continue statement transfers control directly to the conditional expression that governs the loop. In a for loop, control jumps first to the update expression (such as i++) and then to the loop condition.

Loop type Where control goes after continue
for First to the update expression (i++), then to the condition check
while Straight to the condition check at the top of the loop
do-while To the condition check at the bottom of the loop

The continue statement is allowed only inside a loop. If you write it anywhere else, the code will not compile — the compiler reports the error continue outside of loop.

Watch out

In a while loop, the counter is incremented inside the loop body. If continue fires before the line that increments the counter, the counter never changes and the condition is re-checked with the same value — the result is an infinite loop. A for loop does not have this problem: its update expression runs on every iteration.

Example: Printing Only Odd Numbers

In the following example, only odd numbers are printed to the console. When the number is even, continue ends the current iteration early, so System.out.print is never reached:

public class ContinueExample {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                continue;
            }
            System.out.print(i + " ");
        }
    }
}

Program output:

1 3 5 7 9

Labeled continue in Java

The continue statement can also be used with a label — this lets you end the current iteration of an outer loop instead of the inner one. In the following example, the outer loop is labeled outer. When continue outer; is reached, the outer loop immediately proceeds to its next iteration. Without the label, only the inner loop would be affected:

public class ContinueLabelExample {
    public static void main(String[] args) {
        outer:
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                if (j > i) {
                    System.out.println();
                    continue outer;
                }
                System.out.print(" " + (i * j));
            }
        }
        System.out.println();
    }
}

The program prints a "triangle" of the products i * j: as soon as j becomes greater than i, the current row ends and the next iteration of the outer loop begins:

 0
 0 1
 0 2 4
 0 3 6 9
 0 4 8 12 16
 0 5 10 15 20 25
 0 6 12 18 24 30 36
 0 7 14 21 28 35 42 49
 0 8 16 24 32 40 48 56 64
 0 9 18 27 36 45 54 63 72 81

The label must be placed immediately before the loop it refers to. A label is any valid Java identifier followed by a colon.

continue vs break

Both are jump statements, but they behave differently: continue skips the rest of the current iteration and lets the loop carry on, while break terminates the loop completely — execution resumes at the first statement after the loop. For a detailed comparison of break, continue, and return, see the lesson on the Java break statement.

Frequently Asked Questions

What does the continue statement do in Java?

It skips the rest of the loop body in the current iteration and moves to the next one: in while and do-while loops control goes straight to the condition check, and in a for loop it goes to the update expression first and then to the condition. The loop keeps running.

Can I use continue outside a loop or inside a switch?

Outside a loop — no: the compiler reports "continue outside of loop". If a switch is placed inside a loop, then continue in a case branch is legal and applies to the loop, not to the switch — unlike break, which would only exit the switch.

When do I need continue with a label?

When, inside nested loops, you need to end an iteration of the outer loop rather than the inner one. A plain continue only affects the nearest enclosing loop; continue outer; jumps to the next iteration of the loop marked with the outer label.

Does continue hurt code readability?

A single continue at the top of the loop body that filters out unwanted values usually makes the code cleaner than a large nested if. Trouble starts when continue statements are scattered across a long loop body or labels are used without a real need — in those cases it is better to extract the logic into a separate method.

Comments

Please log in or register to have a possibility to add comment.