Continue Statement with Example in Java

In this class, We discuss Continue Statement with Example in Java.

The reader should have prior knowledge of loops in Java. Click Here.

Continue Statement:

If we want to jump to the next iteration in the loop, we use the continue statement.

We take an example for the continue statement.

Example:

for(i=1; i<=10; i++)

{

if(i==5)

{

continue;

}

Remaining Code

}

In the above loop, we have an if statement followed by some code.

When we enter the loop, the execution checks the if condition, and the code is written after “if.”

The loop executes ten times.

Executing loop one time we call an iteration.

The if condition is true in the fifth iteration, so it executes the continue statement.

After executing the continue statement, the execution moves to the next iteration by skipping the remaining execution of the body.

So to jump to the next iteration, we apply the continue statement.

The below example will help the reader to understand the continue statement.

Our previous class discussed examples to display 2 to 10 tables.

Example:

Display 2 to 10 tables. We need to skip displaying the 5th and 8th tables.

The below diagram shows the code.

In the above program, the outer loop will jump to the next iteration when I equal 5 or 8.

We use the continue statement to skip the inner loop from displaying the 5th and 8th tables.

Please elaborate on the code step-by-step for better understanding.