Java Break Statement Example
Chapter:
Control Statements
Last Updated:
06-07-2016 04:12:03 UTC
Program:
/* ............... START ............... */
public class JavaBreakExample {
public static void main(String args[]) {
for (int i = 0; i < 100; i++) {
if (i == 10)
break; // terminate loop if i is 10
System.out.println("i: " + i);
}
System.out.println("Loop complete.");
}
}
/* ............... END ............... */
Output
i: 0
i: 1
i: 2
i: 3
i: 4
i: 5
i: 6
i: 7
i: 8
i: 9
Loop complete.
Notes:
-
Break Statement in Java terminates the loop and comes out the loop when it is called.
- Break statement used to terminate a case in the switch statement.
- Break Statement is mostly used for for Loop, while Loop,switch statment and do-while loop.
Tags
Java break, Java