by Dinesh Thakur Category: Operators and Expressions

This Java continue statement with label example shows how to use java continue statement to skip to next iteration of the labeled loop.


Here is the Java Example for the program JavaContinueWithLabelExample :

import java.util.Scanner;

public class JavaContinueWithLabelExample
{
      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)
                               {
                                 continue firstforloop;
                               }
                   }
               }
         }
catch (Exception e){}
   }
}

Java continue 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.