Computer >> Computer tutorials >  >> Programming >> Javascript

The while loop in Javascript


The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. Once the expression becomes false, the loop terminates.

The while loop in Javascript

Example

For example −

let i = 0;
while (i < 5) {
   console.log("Hello");
   i = i + 1;
}

Output

This will give the output −

Hello
Hello
Hello
Hello
Hello