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.

Related Posts

  • 27 April

    Switch case in java

    Switch case in java is alternative to if else if ladder. It is used to execute statements based on some conditions. Syntax of Switch case in java [crayon-603bc6f347d04980605101/] Let’s understand it with the help of simple example. We are going to print weekday based on integer. 0 represents Sunday, 1 represents Monday and so on.. […]

  • 27 April

    if else statement in java

    If else statements in java are used to test some conditions. It evaluates a condition to be true or false. There are three types of if statements. If statement If else statement If else if ladder statement Simple If statement [crayon-603bc6f34831c910658925/] For example: [crayon-603bc6f348322807471132/] Output: Price is greater than 10 You can write single line followed […]

  • 27 April

    Do While loop in java with example

    There are several looping statements available in java. One of them is do while loop in java. While loop is used to execute some statements repeatedly until the condition returns false. If the number of iterations is not known beforehand, while the loop is recommended. In Do while loop, loop body is executed at least […]

  • 13 April

    Java break statement example

    Break statement is one of the different control statements which we use very often. If break statement is found in loop, it will exit the loop and execute the statement following the loop. Let’s take very simple example: Java break statement example You want to search for the element in an array and if element […]

  • 05 April

    While loop in java with example

    There are several looping statements available in java. One of them is while loop in java. While loop is used to execute some statements repeatedly until condition returns false. If number of iterations are not known beforehand, while loop is recommended. The syntax for while loop in java [crayon-603bc6f348bd7150424083/] Let’s take a very simple example: […]

  • 05 April

    For loop in java with example

    There are several looping statements available in java. One of them is for loop in java. For loop in java is used to execute some statements repeatedly until the condition returns false. There are three parts to for loop. Initialization Condition Increment or decrement Syntax for for loop in java [crayon-603bc6f34904c470157087/] Initialization: Initialization statement executes […]

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.