Executes a statement block once, and then repeats execution of the loop until a condition expression evaluates to false.
Syntaxdo {
statement
} while (expression) ;
In the following example, the statements in the do…while loop continue to execute as long as the variable i
is less than 10.
var i = 0;
do {
document.write(i + " ");
i++;
} while (i < 10);
In the following example, the statements inside the loop are executed once even though the condition is not met.
var i = 10;
do {
document.write(i + " ");
i++;
} while (i < 10);
Remarks
Unlike the while statement, a do…while loop is executed one time before the conditional expression is evaluated.
On any line in a do…while block, you can use the break statement to cause the program flow to exit the loop, or you can use the continue statement to go directly to the while expression.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4