Jump to content

JavaScript/Reserved words/continue

From Wikibooks, open books for an open world
Previous: const Reserved words Next: debugger

The continue keyword

[edit | edit source]

The continue keyword interrupts the loop immediately, going to the starting line as if the loop had been finished to the end and incrementing the loop variable, if any.

Examples

[edit | edit source]
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) {
      continue;
    }
  }
returns the following:
result = 3
result = 6

See also

[edit | edit source]
Previous: const Reserved words Next: debugger