by Dinesh Thakur Category: Operators and Expressions

This Java break statement with label example shows how to use java break statement to terminate the labeled loop.

Here is the Java Example for the program JavaBreakWithLableExample :

import java.util.Scanner;

public class JavaBreakWithLableExample
{
           public static void main(String[] args)
       {
          try
                   {
             int n ;
             System.out.println("Enter an the Starting Number");
             Scanner scan = new Scanner(System.in);
             n = scan.nextInt();
             if ( n < 0 )
             System.out.print("Please Enter Number should be non-negative.");
             else
                  {
                 firstforloop: for (int i = n;i<=100; i++)
                         {
                          secondforloop: for (int j = n; j < i; j++)
                             {
                                if (i % j == 0)
                                  {
                                     continue firstforloop;
                                  }
                             }
                                System.out.print(i +",");
                                if (i == 61)
                                  {
                                    break firstforloop;
                                  }
                        }
                     }
               }
catch (Exception e){}
  }
}

Java break statement with label 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.