How to use do...while loop in Javascript

Description

The do-while statement is a post-test loop. The body of the loop is always executed at least once.

Here's the syntax:


do { 
    statement 
} while (expression);

Example

And here's an example of its usage:


var i = 0; 
do { /*from   www . ja  v a2s  .co  m*/
    i += 2; 
    document.writeln(i);
} while (i < 10); 

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions