Continue-Statement-In-Java .

In this session i have discussed continue statement in Java .


The continue is a keyword in Java which is used in loop . When a continue statement is encountered inside a loop, control jumps to the beginning of the loop for next iteration, skipping the execution of statements inside the body of loop for the current iteration .

Example : Write a program that will demonstrate the break statement in loop .

class Hello{ 
         
    public static void main(String args[]){  

            for(int i=1;i<10;i++){
            
                if(i==6){
                
                    continue;
                }
                System.out.print(i);
                System.out.print(" ");
            }
    }
}
    OUTPUT : 1 2 3 4 5 7 8 9 10
    

6 is missing in above program because of continue statement


Example : Write a program that will demonstrate the continue statement in nested loop .

class Hello{ 
         
    public static void main(String args[]){  

         int i=1,j=1;    
         for(i=1;i<=3;i++){
               
             for(j=1;j<=3;j++){
                 
                if(i==2 && j==2){
                    
                   continue;    
                }    
                System.out.print("\n"+i+" "+j);    
             }    
         }
    }
}
    
    OUTPUT : 1 1
             1 2
             1 3
             2 1
             3 1 
             3 2
             3 3
    

Example : Write a program that will demonstrate the continue statement in while loop .

class Hello{ 
         
      public static void main(String args[]){  

           int i=1;
            while(i<=10){
            
                if(i==6){
                
                    i++;
                    continue;
                }
                System.out.print(i);
                System.out.print(" ");
                i++;
            }
      }
}
    
    OUTPUT : 1 2 3 4 5 7 8 9 10
    

Welcome to AndroidATPoint.

back image                     next image