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){}
}
}