Statements and declarations
while statement
Tests before each iteration and runs the body while the test is truthy. A falsy initial test results in zero executions. Ensure the changing state can reach a stopping condition.
Formal Syntax & Structure
javascript syntaxjavascript
while (test) { body }Working Example
Example Snippetjavascript
let n = 2; while (n > 0) { console.log(n--); }