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.

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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 15-Jun-2020

167 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements