A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/statements/while below:

while · WebPlatform Docs

while Summary

Executes a statement or series of statements while a specified condition is true.

Syntax
while ( expression ) {
  statements
}
expression
Required. A Boolean expression that is checked before each iteration of the loop. If expression is true, the loop is executed. If expression is false, the loop is terminated.
statements
Optional. One or more statements to be executed if expression is true.
Examples
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 Attributions

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