JavaScript/Reserved words/break

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: boolean Reserved words Next: byte

The break keyword[edit]

The break keyword interrupts a loop immediately.

Examples[edit]

Crystal Clear action apply.png The code
  var array = [2, 3, 5, 7, 10, 11], result = 1;

  for (var i = 0; i < array.length; i++) {
    result += array[i];
    console.log("result = " + result);
    if (result%2 == 0) {
      break;
    }
  }
returns the following:
result = 3
result = 6

See also[edit]

Previous: boolean Reserved words Next: byte