Java continue statement is used to skip the current iteration of a loop. Continue statement in java can be used with for, while and do-while loop.

Java continue statement

When continue statement is used in a nested loop, it only skips the current execution of the inner loop. Java continue statement can be used with label to skip the current iteration of the outer loop too. Let’s have a look at some continue java statement examples.

Java continue for loop

Let’s say we have an array of integers and we want to process only even numbers, here we can use continue loop to skip the processing of odd numbers.

Java continue while loop

Let’s say we have an array and we want to process only index numbers divided by 3. We can use java continue statement here with while loop.

Java continue do-while loop

We can easily replace above while loop code with do-while loop as below. Result and effect of continue statement will be same as above image.

Java continue label

Let’s have a look at java continue label example to skip the outer loop processing. We will use two dimensional array in this example and process an element only if all the elements are positive numbers.

java continue label

Java continue important points

Some important points about java continue statement are;

  1. For simple cases, continue statement can be easily replaced with if-else conditions but when we have multiple if-else conditions then using continue statement makes our code more readable.
  2. continue statement comes handy incase of nested loops and to skip a particular record from processing.

I have made a short video explaining java continue statement in detail, you should watch it below.

Reference: Oracle Documentation

By admin

Leave a Reply