1//Java Program to demonstrate the use of break statement
2//inside the for loop.
3public class BreakExample {
4public static void main(String[] args) {
5 //using for loop
6 for(int i=1;i<=10;i++){
7 if(i==5){
8 //breaking the loop
9 break;
10 }
11 System.out.println(i);
12 }
13}
14}
1public class Test {
2
3 public static void main(String args[]) {
4 int [] numbers = {10, 20, 30, 40, 50};
5
6 for(int x : numbers ) {
7 if( x == 30 ) {
8 break;
9 }
10 System.out.print( x );
11 System.out.print("\n");
12 }
13 }
14}
15
1public void someMethod() {
2 //... a bunch of code ...
3 if (someCondition()) {
4 return; //break the funtion
5 }
6 //... otherwise do the following...
7}