EN
JavaScript - do...while statement
0
points
In this article, we would like to show you how to use the do...while statement in JavaScript.
Syntax
do {
// statement
} while (condition);
Description
The do...while
statement is used to create a loop that executes a specified block of code at least once, and then repeatedly executes the block until the test condition
evaluates to false
.
Practical example
In this example, the do...while
loop iterates at least once and reiterates until i
is no longer less than 3
.
// ONLINE-RUNNER:browser;
let i = 0;
do {
++i;
console.log(i);
} while (i < 3);
Output:
1
2
3