Javascript Reference
Categories: Operators

javascript Operators while

@July 9, 2008, 4:09 p.m.
while Firefox/Netscape/NN 2 IE 3 ECMA 1  

 

  

Executes statements in a loop as long as a condition is true. Because the condition is tested at the beginning of the loop, it is conceivable that under the right conditions, the statements inside the loop do not execute. It is imperative that the expression that makes up the condition have some aspect of its value potentially altered in the statements. Otherwise an infinite loop occurs.

 
Example
 
var i = 0;
while (!document.forms[0].radioGroup[i].checked) {
  i++;
}
alert("You selected item number " + (i+1) + ".");

Powered by Linode.