Java continue statement example

continue statement is one of the different control statements which we use very often.If continue statement is found in loop, it will continue the current iteration and will not execute statements following continue statement. It is generally used to skip current iteration on the basis of some condition.
Let’s take very simple example:

Java continue statement example:

You have elements in the array from 1 to 10 but you want to print only odd numbers and skip even numbers. In this case, if we get an even number, we will skip that iteration so loop won’t print even number.

When you run above program, you will get below output:

1 3 5 7 9

Labeled continue statement:

Labeled break continue is used when you want to continue labeled for loop rather than current loop.

For example:

You have a two-dimensional matrix which contains only 0 and 1. You want to skip a row if row starts with 1.

When you run above program, you will get below output:

Skipping row 0as it started with 1
0 0 0
Skipping row 2as it started with 1
0 1 1

That’s all about Java continue statement example.

Add Comment