Export (0) Print
Expand All

while Statement (JavaScript)

Executes a statement until a specified condition is false.

while (expression)


Required. A Boolean expression checked before each iteration of the loop. If expression is true, the loop is executed. If expression is false, the loop is terminated.


Optional. One or more statements to be executed if expression is true.

The while statement checks expression before a loop is first executed. If expression is false at this time, the loop is never executed.

The following example illustrates the use of the while statement.

function BreakTest(breakpoint) {
   var i = 0;
   while (i < 100) {
      if (i == breakpoint)

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Community Additions

© 2014 Microsoft