Break statement in Java
Java break statement
As the name suggests, the break statement is used to break the current flow of the program and transfer the control to the next statement outside a loop or switch statement. However, it breaks only the inner loop in the case of the nested loop.
The break statement cannot be used independently in the Java program, i.e., it can only be written inside the loop or switch statement.
The break statement example with for loop
Consider the following example in which we have used the break statement with the for loop.
BreakExample.java
Output:
0 1 2 3 4 5 6
break statement example with labeled for loop
Calculation.java
Output:
0 1 2 3 4 5
Comments
Post a Comment