by Dinesh Thakur

This Java break statement example shows how to use java break statement to terminate the loop. The Java break statement has two forms labeled and unlabeled. in the below example You can see unlabeled form.

Here is the Java Example for the program JavaBreakStatementExample :

public class JavaBreakStatementExample

{
      public static void main(String[] args)
     {
        try
         {
              int[] arrayOfInts = { 92, 37, 31, 59, 112, 176, 230, 81, 62, 7 };
              int search = 112;
              System.out.print("Elements before 112 are : ");
              for(int i=0; i < arrayOfInts.length ; i ++)
                 {
                    if(arrayOfInts[i] == search)
                       break;
                    else
                      System.out.print(arrayOfInts[i] + " , " );
                 }
          }
                    catch (Exception e){}
    }
}

Java break statement example