while loop : while : Statement JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Statement » while »

 

while loop












The while loop can be summarized as while the expression evaluates to true, execute the statements in the loop.

Once the last statement in the loop is executed, go back to the top of the loop and evaluate the expression again.

When the expression evaluates to false, the next line of code following the while loop structure is executed.

Because the expression is evaluated before the loop, it is possible the loop will never be executed.

The format of the while loop looks like the following:








while (expression)
    {
      statement;
    }














<html>
    <SCRIPT LANGUAGE='JavaScript'>
    <!--
    var light = "red";             
    var counter = 1;               
    var carsInLine = new Array();  

    while (counter <= 5)
    {
      document.write("Car ",counter," approaches intersection.<BR>");
      counter++;   //Next car
    }
    //-->
    </SCRIPT>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Statement
» while