Continue Statement in Java

 
The continue statement is a control statement which is used to skip the following statement in the body of the loop and continue with the next iteration of the loop.

Types of continue statement:

1. Unlabeled continue statement: is used to skip the following statement in the body of the loop when specific condition returns true.
2. Labeled continue Statement: is used to skip the following statement in the body of the specific loop based on the label when specific condition returns true.

Syntax of Unlabeled continue statement:

for( initialization; condition; statement){ 
        //Block of statements
         if(condition){
                continue;
         }
}

Program to use for loop Continue example in java.

/**
 * Program to use for loop Continue example in java.
 * @author javawithease
 */
public class ForLoopContinueExample {	
	static void forLoopContinueTest(int num){
		//For loop test
		 for(int i=1; i<= num; i++){
			 if(i==6){
				 //Continue the execution of for loop.
				 continue;
			 }
			 System.out.println(i);            
                }
	}	
 
	public static void main(String args[]){ 
		//method call 
		forLoopContinueTest(10); 
	}
}

Output:

1
2
3
4
5
7
8
9
10

Download this example.