Break

La instrucción break sirve para abandonar una estructura de control, tanto de alternativas (IF - ELSE, switch) como de bucles (for, do-while, while). En el momento que se ejecuta la instruccion break, el control del programa sale de la estructura en la que se encuentre.

Vamos a ver un ejemplo con un bucle while:

public class break_while {
  public static void main(String[] args) {
    int i=0;
        
    while (i<10){
        System.out.println("i="+i);
        i++;
        break;
    }
  }
}

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options