Java Program For Break and Label Break vs Continue and Label Continue

Free Java courses with 37 real-time projects - Learn Java

Program 1

package testcoreproject;


public class TestCoreProject {

    
    public static void main(String[] args) 
    {
           int i,j;
           one:for(i=1;i<=5;i++)
         {
             two:for(j=1;j<=5;j++) 
             {      
                 
                 System.out.print(i+" "+j);
                 System.out.println();
                 if(i==j)
                   break one;
                 
             } 
          System.out.println();   
         }
         
    }
    
}

Program 2

package testcoreproject;

public class TestContinue 
{
    public static void main(String[] args) 
    {
         int i,j;
         one:for(i=1;i<=5;i++)
         {
             two:for(j=1;j<=5;j++) 
             {      
                 if(i==j)
                   continue one; 
                 System.out.print(i+" "+j);
                 System.out.println();
                
                 
             } 
          System.out.println();   
         }
    } 
    
}

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *