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

The do…while loop in Javascript


The do...while loop is similar to the while loop except that the condition check happens at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false.

The do…while loop in Javascript

For example,

Example

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

This will give the output −

Output

Hello
Hello
Hello
Hello
Hello