by Dinesh Thakur Category: Operators and Expressions

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



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.