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 statements. 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 that contains only 0 and 1. You want to skip a row if the 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.