continue Statement in Java

28 Jul 2025 | 6 min read

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.

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.

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

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: continue Statement

//Java Program to demonstrate the use of continue statement inside the for loop.

Output:

1
2
3
4
6
7
8
9
10

As shown in the output above, the number 5 is not printed to the console because the loop is continued when it reaches 5.

Java continue Statement with Inner Loop

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

//Java Program to illustrate the use of continue statement inside an inner loop

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.

Output:

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

Java continue Statement with While Loop

Output:

1
2
3
4
6
7
8
9
10

Java continue Statement with do-while Loop

Output:

1
2
3
4
6
7
8
9
10

Practical Applications of Continue Statement

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.

Output:

1
3
5
7
9

Advantages of Continue Statement

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:

It skips over null entries cleanly without cluttering the loop body.

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

Disadvantages of Continue Statement

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:

It works, but it is hard to read at a glance. Sometimes, an if with combined conditions might be clearer.

Conclusion

The continue statement in Java is a powerful tool for controlling the flow of loops. By skipping specific iterations based on conditions, it helps improve the readability and efficiency of the code.

Whether filtering data, avoiding unnecessary computations, or managing complex nested loops, the continue statement proves to be a versatile and valuable tool in a Java programmer's toolkit. Understanding and utilizing continue effectively can lead to cleaner, more maintainable, and efficient code.

Java continue Statement MCQs

1. What does the continue statement do in a loop?

  1. Terminates the loop
  2. Skips the current iteration and moves to the next
  3. Restarts the loop
  4. Exits the method
 

Answer: B

Explanation: The continue statement skips the remaining code in the current iteration and jumps to the next iteration of the loop.


2. In which types of loops can the continue statement be used?

  1. Only for loops
  2. Only while loops
  3. for, while, and do-while loops
  4. Only do-while loops
 

Answer: C

Explanation: Java allows continue in all loop types. In for loops, it jumps to the update step; in while and do-while, it re-evaluates the condition.


3. Can the continue statement be used in nested loops?

  1. Yes, it affects all loops
  2. No, only single loops
  3. Yes, but only the innermost loop
  4. Yes, but only the outermost loop
 

Answer: C

Explanation: continue only affects the loop in which it is directly placed. In nested loops, it skips the current iteration of the innermost loop.


4. What happens when continue is used in a while loop?

  1. Control jumps to the update statement
  2. Control jumps to the Boolean condition
  3. Loop terminates
  4. Loop restarts
 

Answer: B

Explanation: In a while loop, continue causes control to jump to the condition check, skipping the rest of the loop body.


5. What is the output of the following code?

  1. 0 1 2 3 4
  2. 0 1 3 4
  3. 1 2 3 4
  4. 0 1 2 4
 

Answer: B

Explanation: When i == 2, continue skips the System.out.print() call, so 2 is not printed.


Next TopicJava Comments
 
 




close