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.
xxxxxxxxxx
1
do {
2
// statement
3
} while (condition);
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
.
In this example, the do...while
loop iterates at least once and reiterates until i
is no longer less than 3
.
xxxxxxxxxx
1
let i = 0;
2
3
do {
4
++i;
5
console.log(i);
6
} while (i < 3);
Output:
xxxxxxxxxx
1
1
2
2
3
3