Friday, November 17, 2017

Java Break Statement with Example

The Java break is utilized to break circle or switch explanation. It breaks the present stream of the program at the indicated condition. If there should arise an occurrence of the inward circle, it breaks just the internal circle
  • At the point when the break articulation is experienced inside a circle, the circle is promptly ended and the program control resumes at the following proclamation following the circle. 
  • It can be utilized to end a case in the switch articulation (canvassed in the following section).
    java Break Statement with Example


    Example:

    public class db
    {  
             public static void main(String[] args)
           
           {  
                 for(int d=1;d<=20;i++)
                {  
                     if(d==7)
                    {  
                         break;  
                    }
      
                    System.out.println(d);  
                }  
           }  
    }  
        
    Output:
    1
    2
    3
    4
    5
    6

    • Java Break Statement with Inner Loop

    It breaks inward circle just on the off chance that you utilize break proclamation inside the internal circle.
    public class db 
               public static void main(String[] args)
              { 
                       for(int i=1;i<=3;i++)
                      {    
                            
    for(int j=1;j<=3;j++)
                                 {    
                                            
    if(i==2&&j==2)
                                                {    
                                                        
    break;    
                                                }  
                                         
      System.out.println(i+" "+j);    
                                   }  
                        }  
                }
    }  

    Output:
    1 1
    1 2
    1 3
    2 1
    3 1
    3 2
    3 3


    No comments:

    Post a Comment

    Top 200+ Core Java Interview Questions And Answers For 2019

    Most Popular Java Interview Questions Given below is a comprehensive list of most important and commonly asked basic and advanced Java p...