Tuesday, November 25, 2014

Breaking loop in java

In example, Test class has a main method and a for loop inside it and printing the looped value on console and break syntax will hault the execution of loop.
 public class test2  
 {  
      public static void main(String args[])  
      {  
           for(int x=5;x<=10;x++)  
           {  
                if(x%10==0)  
                {  
                     System.out.println(x);  
                     break;  
                     System.out.println(x);  
                }  
           }  
      }  
 }  

No comments: