Tutorials

Java Loop Control


Java continue statement


In java continue statement is used to continue the loop at a specified condition.

 

When continue statement is encountered inside a loop then:

  • all the statement after continue statement in the current iteration is ommited. 
  • loop control will go to the beginning of the loop for next iteration.

Let's learn how it continues the loop while skipping rest of the code with examples.

Example 1:

package Statement;

public class ContinueExample {

   public static void main(String[] args) {
      for(int num=1; num<=6; num++){
         if(num==3){
           continue;
         }
        System.out.println(num);
     }
  }
}

OUTPUT:
1
2
4
5
6
 
 
Example 2:
 
package statement;

public class ContinueExample {

     public static void main(String[] args) {
        for(int num=2; num<=4; num++){
            for(int num1=2; num1<=4; num1++){
                if(num==3 && num1==3){
                continue;
                }
             System.out.println(num+ "&"+num1);
           }
       }
   }
}

		
 
OUTPUT:
2&2
2&3
2&4
3&2
3&4
4&2
4&3
4&4
 
break vs continue statement
 


Please Share this page
Views : 82
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!