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:
Syntax of continue:
1 | continue; |
Example: Java program to demonstrate the continue statement:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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:
1 | 0 1 2 3 4 6 7 8 9 10 |