Break Statement in Java

 
The break statement is a control statement which is used to jump out of the loop.

Types of break statement:

1. Unlabeled Break statement: is used to jump out of the loop when specific condition returns true.
2. Labeled Break Statement: is used to jump out of the specific loop based on the label when specific condition returns true.

Syntax of Unlabeled Break statement:

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

Program to use for loop break statement example in java

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

Output:

1
2
3
4
5

Download this example.