Continue Statement in Java with Label

 
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 Labeled continue statement:

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

Program to use for loop Continue label example in java.

/**
 * Program to use for loop Continue label example in java.
 * @author javawithease
 */
public class ForLoopContinueLabelExample {	
	static void forLoopContinueLabelTest(int num1, int num2){
		//For loop continue label test
		Outer:
		 for(int i=1; i<= num1; i++){
			 Inner:
			 for(int j=1; j<= num2; j++){
			  if(i + j == 4){
			    //Continue the execution of Outer for loop.
			    continue Outer;
			   }
			   System.out.println(i + j);    
			 }			         
                }
	}	
 
	public static void main(String args[]){ 
		//method call 
		forLoopContinueLabelTest(3, 2); 
	}
}

Output:

2
3
3

Download this example.