Repeat

While Loop

JavaScript

 

While loop

ECMAScript 5
var count = 5;

while (count > 0) {
    count--;
    console.log(count);
}

The code inside the while block runs as long as the condition count > 0 evaluates to true.

This will print 4 3 2 1 0 on Console.

 

Single While loop Statement

ECMAScript 5
var count = 5;

while (count > 0)
    console.log(count--);

If you only have one statement in your while blocks, you can drop the curly braces { }.

This will print 5 4 3 2 1 on Console.