Java – continue statement with Example

It is one of the jump statement in java. It is used in loops to jump immediately to the next iteration of the loop. continue is used with while loop or do/while loop and with for loop.

When continue is used inside for loop then the control immediately jumps to the increment or decrement part of the for a loop. And when used inside while loop or do/while loop then the control immediately jumps to the condition part.

Flowchart for Java continue statement:

Continue statement in java

Syntax of continue:

continue; 

Example: Java program to demonstrate the continue statement:

 public class ContinueTest 
 {
    public static void main(String args[])
    {
    for (int i=0; i<=10; i++)
    {
     if (i == 5)
     {
      continue; // skip the rest of the code
     }

    System.out.print(i+" ");
    }
    }
 }

Output:

 0 1 2 3 4 6 7 8 9 10