4
Q:

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!
*/
2
public class Test {

   public static void main(String args[]) {
      int [] numbers = {10, 20, 30, 40, 50};

      for(int x : numbers ) {
         if( x == 30 ) {
            break;
         }
         System.out.print( x );
         System.out.print("\n");
      }
   }
}
3
int i = 0;
while (i < 10) {
  if (i == 4) {
    i++;  //why do I need this line ?
    continue;
  }
  System.out.println(i);
  i++;
}
1
public void someMethod() {
    //... a bunch of code ...
    if (someCondition()) {
        return; //break the funtion
    }
    //... otherwise do the following...
}
0

New to Communities?

Join the community