Groovy - Continue Statement


Advertisements

The continue statement complements the break statement. Its use is restricted to while and for loops. When a continue statement is executed, control is immediately passed to the test condition of the nearest enclosing loop to determine whether the loop should continue. All subsequent statements in the body of the loop are ignored for that particular loop iteration.

The following diagram shows the diagrammatic explanation of the continue statement −

Continue Statement

Following is an example of the continue statement −

Live Demo
class Example {
   static void main(String[] args) {
      int[] array = [0,1,2,3];
		
      for(int i in array) {
         if(i == 2)
         continue;
         println(i);
      }
   }
}

The output of the above code would be −

0 
1 
3

groovy_loops.htm
Advertisements