Name

do/while — NN 4 IE J3 ECMA n/a

Synopsis

Executes statements in a loop while a condition is true. Because the condition is tested at the end of the loop, the statements inside it are always executed at least one time. 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

do {
    statements
} while (condition)

Example

var i = 1
do {
    window.status = "Loop number " + i++
} while (i <= 10)
window.status = ""

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.