Break statement in for each loop in java

Java Programming Language / Decision Making and Looping in java

1076

Program:

class BreakStatementInForEachLoop {

   public static void main(String args[]) {
      int [] numbers = {12, 14, 30, 44, 56};

      for(int x : numbers ) {
         if( x == 30 ) {
            break;
         }
         System.out.print( x );
         System.out.print("\n");
      }
   }
}

Output:

12
14
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.