Executes a statement or series of statements while a specified condition is true.
Syntaxwhile ( expression ) {
statements
}
var i = 0;
while (i < 5) {
console.log("This runs 5 times");
i++;
}
var i = 0;
while (i < 100) {
if (i == 5) {
break;
}
console.log("This happens 5 times");
i++;
}
Usage
The while statement checks the expression before a loop is first executed. If expression is false at this time, the loop is never executed.
The while statement keeps iterating until the conditional expression returns false, or encounters a break statement.
It’s essential that the expression can become false or that that loop is terminated with the break statement to prevent an infinite loop.
See also Other articles Specification 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