Name

while — NN 2 IE J1 ECMA 1

Synopsis

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.

Syntax

while (condition) {
    statements
}

Example

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

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.