while

The while loop iterates through a block of code as long as a specified condition is true.

Syntax

          while (condition) {
  // statements
} 

        

Example

          var i = 0;
while ( i < 5 ) {
    x = x + "The number is " + i;
    i++;
}