Break and Continue





Break :

The break statement in Java has the following two usage:
1. in loops
2. in switch - case

  • The break statement stops the current iteration of loop and exit.

  • It can be use to terminate a case in switch.

Example :

class BreakDemo
{  
 public static void main(String []arg)
 {  
  for(int i=1;i<=10;i++)
   {  
     if(i==5)
      {  
       break;  
      }  
    System.out.println(i);  
  }  
  System.out.println("End");
 }  
}          
OUTPUT:
1
2
3
4   
End 

NOTE : Break, only terminates the current loop in which it occurs.

Continue :

The continue statement stops the current iteration of loop and continue the next iteration.

Exmple :

class ContinueDemo
{
 public static void main(String []arg)
 {  
  for(int i=1;i<=10;i++)
   {  
    if(i==5)
    {  
     continue;  
    }  
    System.out.println(i);  
   } 
 }  
}          
OUTPUT:
1
2
3
4
6
7
8
9
10         

NOTE : Continue, use only within loops.

Next topic is user-input




 

Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in


Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in



CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved