While Loop in JavaScript

While Loop executes a set of statements as long as the conditions is true.
while (variable<maxValue)
 // statements

Example 1 : Basic While Loop
<script type='text/javascript'>
    var light = "red";             
    var counter = 1;               
    while (counter <= 5)
      document.write("Car ",counter," approaches intersection.<BR>");
      counter++;   //Next car

Note : If counter is not incremented, Car1 will always approach the intersection.