Java continue statement with Loop



Example

Following is an example

Live Demo

public class Tester {
   public static void main(String args[]) {
      int[] array = {1,2,3,4,5};
     
      for (int i = 0; i < array.length; i++) {
         if(i == 3){
            continue;
         }
         System.out.print(array[i]);
      }  
   }
}

The output will be 1235 as it will skip the loop when i is 4 and continue will move the control back to for loop.


Advertisements