The while Statement



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




Review of Terms Related to This Topic





Definition and Purpose

The while statement is one of JavaScript's program control statements. The conditional expression of the while clause is tested at each iteration of the loop. If the test evaluates to true, then the loop body is executed and continues to execute until the conditional expression returns false.

The while and do/while loops are similar except the while loop's conditional expression is tested at the top. The do/while loop's conditional expression is tested at the bottom.





Statement Syntax


while (expression) statement



More on Syntax and Statement Behavior





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 while statement.





while Statements and Block Statements

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





ECMA-262 Section 12.6.2

The while statement is an ECMAScript core statement and is detailed is section 12.6.2 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).



Top            

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