The do/while Statement

Navigation Aids -- This Page           Navigation Aids -- This Topic           Navigation Aids -- This Site

Review of Terms Related to This Topic

Introduction And Review

The do/while statement is one of JavaScript's program control statements. The loop body is always executed once. This is because the conditional expression in the do/while statement is tested at the bottom of the loop. If the conditional expression tests to be true, then the loop body is executed again and continues to execute until the conditional expression returns false.

The do/while and while loops are similar except the while loop's conditional expression is tested at the top of the loop. If the first time test is false, the loop body will never be executed.

Statement Syntax

do    statement while (expression)

More on Syntax and Statement Behavior

do/while Statements Evaluate to Boolean

The conditional expression of the while clause will evaluate to a boolean. The loop body is executed again and again while the expression evaluates to true. Otherwise, the program flow proceeds to the next sequential statements immediately after the do/while statement.

do/while Statements and Block Statements

The loop body is contained within curly braces. This is a use of the block statement. The do/while statement is just one example of where the block statement may be used.

ECMA-262 Section 12.6.1

The do/while statement is an ECMAScript core statement and is detailed is section 12.6.1 of the ECMAScript Language Specification. Here is a partial extraction of text from this section.

Iteration Statements: An iteration statement consists of a header (which consists of a keyword and a parenthesized control construct) and a body (which consists of one of more statements).


Rx4AJAX        About Us | Topic Index | Contact Us | Privacy Policy | 2008 This Site Built By PPThompson