"while" Loop Statements

This section provides a quick description of the 'while' loop statement.

The "while" statement is a very common loop statement in many programming languages. The JavaScript "while" statement has the following generic syntax format:

while (loop_condition)
   statement or statement_block

A "while" statement is executed as follows:

Step 1: "loop_condition" expression is evaluated as a Boolean value.

Step 2: If "loop_condition" is evaluated to "true", continue with Step 4.

Step 3: If "loop_condition" is evaluated to "false", terminate the loop.

Step 4: Execute "statement" or "statement_block".

Step 5: Continue with Step 1.

There is another form of "while" loop, called "do ... while" loop statement, with the following syntax format:

do
   statement or statement_block
while (loop_condition);

"while" loop statement could be executed infinitely, if the "loop_condition" is always evaluated to "true".

A "break" statement could be used inside the loop statement block to terminate the loop early.

A "continue" statement could be used inside the loop statement block to skip the rest of the block and start the next iteration of the loop.

A tutorial example will be given in the next section showing an example of the "while" loop statement.

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

Flow Control Statements

 What Is a Statement

 Conditional "if" Statements

 Conditional "if" Statement Examples

 "switch ... case" Statements

 "switch ... case" Statement Example

 "for" Loop Statements

 "for" Loop Statement Example

"while" Loop Statements

 "while" Loop Statement Example

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications

 AJAX (Asynchronous JavaScript And XML)

 References

 Full Version in PDF/EPUB