本文档基于 CC协议(Creative Commons Share-Alike License)发布,是developer.mozilla.com, www.mozref.comwww.aptana.com共同劳动的成果。

while

Executes a statement while the specified expression is true.

Syntax

 while (expression)
statement 

Example

 n = 0;
  while (n < 3) {
  n ++;
  doSomething(); //Will "doSomething" three times--until n is no longer less than three.
} 

Remarks

Use a while loop as a shorthand version of a "counter" for loop.