The do...while statement is a loop construct in javaScript that executes a block of code at least once, and then continues to executes the block as long as specified condition evaluates to true. This statement is particularly usefull when you want to ensure that a certain code block executes before checking condition for further iterations.
Syntax
do {
// Code to be executed
} while (condition);
Example:
let count = 0;
do {
console.log("Count: " + count);
count++;
} while (count < 5);
/* Output:
Count: 0
Count: 1
Count: 2
Count: 3
Count: 4
*/
In this example, the do...while loop starts by executing the block of code inside the do statement. It prints the current value of count and then increments it by 1. The loop continues executing as long as the condition count < 5 evaluates to true. Once the condition becomes false, the loop terminates.