While loop:

While loop executes a block of code as long as the given condition is true.

Syntax:

While(condition)
{
   //some code goes here.
}

Example for while loop:

The following example displays numbers from 100 to 1.
var num=100;
var res='';
while (num>0) {
res=res+num+'\n';
num--;
}
alert(res);