In this example, We will discuss about the use and implementation of break statement in java.
break Statement in Java
In this example, We will discuss about the use and implementation of break statement in java. Break statement is used to terminate the loop coded inside the program. In this program break statement is terminating the for loop when the if condition defined under the for loop is satisfied.
Example: BreakExample.java
package com.devmanuals2; public class BreakExample { public static void main(String[] args) { int j; for (j = 1; j < 10; j++) { if (j == 5) { System.out.println("Break now"); break; } System.out.println(j); } } }
Output:
1 2 3 4 Break now |
[ 0 ] Comments