JavaScript/Reserved words/while

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

The do keyword[edit]

The while clause includes a condition that determines when the do loop will end.

Examples[edit]

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

  do {
    result += array[i++];
	
    if (result%2 == 0) {
      continue;
    } else if (result > 20) {
      break;
    } else {
      console.log("result = " + result);
    }
  } while (i < array.length)
returns the following:
result = 3
result = 11

See also[edit]

Previous: volatile Reserved words Next: with