//Conclusion
break == jump out side the loop
continue == next loop cycle
return == return the method/end the method.
for(int i = 0; i < 5; i++) {
System.out.println(i +"");
if(i == 3){
break;
}
}
System.out.println("finish!");
/* Output
0
1
2
3
finish!
*/
//Java Program to demonstrate the use of break statement
//inside the for loop.
public class BreakExample {
public static void main(String[] args) {
//using for loop
for(int i=1;i<=10;i++){
if(i==5){
//breaking the loop
break;
}
System.out.println(i);
}
}
}
public void someMethod() {
//... a bunch of code ...
if (someCondition()) {
return; //break the funtion
}
//... otherwise do the following...
}
class Test {
public static void main(String[] args) {
// for loop
for (int i = 1; i <= 10; ++i) {
// if the value of i is 5 the loop terminates
if (i == 5) {
break;
}
System.out.println(i);
}
}
}