Java continue statement with Loop

Java Programming Java8Java Technologies Object Oriented Programming

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.

raja
Published on 22-Jan-2018 12:09:15
Advertisements