It is one of the jump statement in java.
This statement is used within the loop or switch cases to terminate that statement or the current loop is immediately stopped and resumes at the next statement followed by a terminated loop. we can also say that it helps to break out from the middle of the loop.
Flowchart for java break statement:
Syntax of break:
1 | break; |
Example: Java Program to demonstrate break statement:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class BreakTest { public static void main(String[] args) { //using for loop for(int i=1; i<=15; i++) { if(i==10) { break; //breaking the loop } System.out.println(i); } } } |
Output
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 |