continue Statement in Java

Last Updated : 30 Dec 2025

The continue statement is used in loop control structure when you need to jump to the next iteration of the loop immediately. It can be used with for loop or while loop.

How to continue Statement Works?

The Java continue statement is used to continue the loop. It continues the current flow of the program and skips the remaining code at the specified condition. In case of an inner loop, it continues the inner loop only. Unlike the break statement, continue only interrupts the ongoing iteration and resumes control at the beginning of the next iteration.

Loops Supported by the continue Statement

We can use Java continue statements in all types of loops, such as for loops, while loops, and do-while loops.

Syntax of continue Statement

It has the following syntax:

When executed, continue causes the loop to skip the remaining code in the current iteration and immediately proceed to the next iteration. In the case of nested loops, continue affects only the innermost loop.

Example of continue Statement

The following example demonstrates the use of the continue statement inside a for loop. When the value of i becomes 5, the continue statement skips the current iteration. As a result, all numbers from 1 to 10 are printed except 5.

Example

Compile and Run

Output:

1
2
3
4
6
7
8
9
10

Java continue Statement with Inner Loop

It continues the inner loop only if we use the continue statement inside the inner loop.

The following example illustrates the use of the continue statement inside an inner loop. When the condition i == 2 and j == 2 is met, the continue statement skips that iteration of the inner loop. The remaining iterations continue normally, so all pairs are printed except 2 2.

Example

Compile and Run

Output:

1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3

Java continue Statement with Labelled for Loop

We can use a continue statement with a label. This feature was introduced in JDK 1.5. Therefore, we can now continue any loop in Java, whether it is an outer loop or an inner loop.

The following example demonstrates the use of a labeled continue statement. When the condition i == 2 and j == 2 is true, continue aa skips the remaining iterations of the current outer loop and moves to the next iteration of the outer loop. All other pairs are printed normally.

Example

Compile and Run

Output:

1 1
1 2
1 3
2 1
3 1
3 2
3 3

Java continue Statement with While Loop

The continue statement with a while loop is used to skip the remaining code in the current iteration and immediately move to the next iteration of the loop when a specified condition is met.

The following example demonstrates the use of the continue statement inside a while loop. When i becomes 5, the continue statement skips that iteration, so 5 is not printed. All other numbers from 1 to 10 are displayed.

Example

Compile and Run

Output:

1
2
3
4
6
7
8
9
10

Java continue Statement with do-while Loop

The continue statement with a do-while loop is used to skip the rest of the code in the current iteration and proceed directly to the next iteration, even though the loop executes at least once before checking the condition.

The following example demonstrates the use of the continue statement inside a do-while loop. When i becomes 5, the continue statement skips that iteration, so 5 is not printed. All other numbers from 1 to 10 are displayed.

Example

Compile and Run

Output:

1
2
3
4
6
7
8
9
10

Practical Applications of Continue Statement

There are several practical applications of the continue statement. Some of them are as follows:

Filtering Data

One common use case for the continue statement is filtering data. Suppose we have a list of numbers, and we want to print only the odd numbers. Using the continue statement, we can easily skip the even numbers.

Example

Compile and Run

Output:

1
3
5
7
9

Advantages of Continue Statement

There are several advantages of the continue statement in Java. Some of them are as follows:

Improves Readability: It helps you avoid deeply nested if-else structures. The logic becomes more direct and easier to follow.

Flexible Control Flow: It enables the efficient handling of unusual instances within loops without altering the primary logic.

Example:

Explanation:

The following example demonstrates using the continue statement in a for-each loop. The array contains some null values. When a null element is encountered, continue skips that iteration, so only non-null names (Alice, Bob, Charlie, Dave) are printed.

Useful for Filtering: We can filter unwanted data items during iteration without extra flags or lists.

Disadvantages of Continue Statement

There are several disadvantages of the continue statement in Java. Some of them are as follows:

Reduce Clarity if Overused: The loop logic may become difficult to understand if continue is used excessively or with complicated conditions, particularly when there are multiple continue statements.

Example:

Explanation:

The following example demonstrates using multiple continue statements in a for loop. The loop skips numbers divisible by 2, 3, or 5. Only numbers that are not divisible by 2, 3, or 5 (1 and 7) are printed


Next TopicJava Comments