Last Updated: 28 May, 2022
In Java, the continue statement is mainly used inside the loops such as for loop, while loop, do-while loop, etc. The purpose of the continue statement is to continue the current running flow of the Java program and skip the rest of the code at the specified condition.
If we are using the continue statement inside the inner loop then it continues the inner loop only it does not affect the outer loop execution flow.
Syntax:
continue;
Execution flow of for loop with continue statement
Example 1 : Java Continue Statement with for Loop
Output
Even No.: 2
Even No.: 4
Even No.: 6
Even No.: 8
Even No.: 10
Example 2 : Java Continue Statement with Inner for Loop
Output
Even No.: 2
Even No.: 4
Even No.: 6
Even No.: 8
Even No.: 10
Even No.: 2
Even No.: 4
Even No.: 6
Even No.: 8
Even No.: 10
Even No.: 2
Even No.: 4
Even No.: 6
Even No.: 8
Even No.: 10
Example 3 : Java Continue Statement with Labelled For Loop
Output
Outer Loop: 1
Outer Loop: 1
Inner Loop: 3
Outer Loop: 2
Outer Loop: 2
Inner Loop: 3
Outer Loop: 3
Outer Loop: 3
Inner Loop: 3
Execution flow of while loop with continue statement
Example 4 : Java Continue Statement with while Loop
Output
Even No.: 2
Even No.: 4
Even No.: 6
Even No.: 8
Even No.: 10
Execution flow of do-while loop with continue statement
Example 5 : Java Continue Statement with do-while Loop
Output
Even No.: 2
Even No.: 4
Even No.: 6
Even No.: 8
Even No.: 10
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com