Groovy – Continue Statement

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments

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 −

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

Next Topic:-Click Here

Leave a Reply