Write a program using break statement. in java code example

Example 1: break java

//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!
*/

Example 2: break a function java

public void someMethod() {
    //... a bunch of code ...
    if (someCondition()) {
        return; //break the funtion
    }
    //... otherwise do the following...
}

Tags:

Java Example