Mega Code Archive

 
Categories / JavaScript Tutorial / Statement
 

Do while

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>