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
Updated on: 2020-06-15T08:50:59+05:30

289 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements