1//Conclusion
2 break == jump out side the loop
3 continue == next loop cycle
4 return == return the method/end the method.
5
6 for(int i = 0; i < 5; i++) {
7 System.out.println(i +"");
8 if(i == 3){
9 break;
10
11 }
12 }
13 System.out.println("finish!");
14/* Output
150
161
172
183
19finish!
20*/
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}
1for (int i = 0; i < 5; i++;) {
2 if(condition) {
3 // Do stuff
4 } else {
5 break; // Exit the loop
6 }
7}
8// After for loop or after break
1 int [] numbers = {10, 20, 30, 40, 50};
2 for(int x : numbers ) {
3 if( x == 30 ) {
4 break;
5 }
6 System.out.print( x );
7 }
8 }
9}