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

Get Job-ready: Java Course with 45+ 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();   
         }
    } 
    
}

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

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