JAVA Break/Continue

The break and continue statements are the jumps statements that are used to skip some statements inside the loop or terminate the loop immediately without checking the test expression .These statments can be used inside any loops  such as for, while, do- while loop.

Break:

The  break statement can also be used to jump out of loop.

for ex:

 import java .util.Scanner;
 public class Learner{
     public static void main(String[]args){
 Scanner sc=new Scanner(System.in);
 int button=sc.nextInt();
 switch(button){
case 1:System.out.println("Hello Learner");
     break;
case 2:System.out.println("Namaste Learner");
    break;
default:System.out.println("Invalid button");        
  }
}
}

Continue:The continue statement breaks one iteration(in the loop),if a specified condition occurs , and continues with the next iteration in the loop.

for ex:

 

 public class Learner{
     public static void main(String[]args){
     for(int i=1;i<=5;i++){
         continue;
     }
     System.out.println(i);
 }