do…while

JavaScript 1.0+ , ECMAScript 1.0, JScript 3.0+ Nav2+, NES3+, IE 4+, Opera 3+ Syntax

do{
  statement;
}while(expression);

Description

The do…while loop always executes the loop once before evaluating the expression for the first time. Once the loop has executed for the first time, the expression, in parenthesis, is evaluated. If true, the loop is executed again. When the expression evaluates to false, the next line of code following the while structure is executed. A statement must be included in the loop that modifies a variable in the expression to prevent an infinite loop. Also, notice that a semicolon (;) must be placed after the right parenthesis.

Example

Listing 6.116 uses the do…while loop to control access through a gate. ...

Get Pure JavaScript 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.