do...while : Do While « Statement « JavaScript Tutorial






do...while loop always executes the loop once before evaluating the expression for the first time.

This difference is seen in the following format:

do
    {
       statement;
    }
    while (expression);

Once the loop has executed for the first time, the expression 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 semicolon (;) must be placed after the rightmost parenthesis.

<html>
    <SCRIPT LANGUAGE='JavaScript'>
    <!--
    var light = "red";             
    var counter = 1;               
      do
      {
          document.write(counter + "<BR>");
          counter++;
      }
      while (counter < 5);
    //-->
</SCRIPT>
</html>








3.7.Do While
3.7.1.do...while
3.7.2.Do While loop
3.7.3.Use do-while loop and prompt dialog to read user input
3.7.4.Use or (||) in do-while condition
3.7.5.Use integer variable to control a do-while loop