The do...while
statement creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
do statement while (condition);
statement
{ ... }
) to group those statements.condition
condition
evaluates to true, the statement
is re-executed. When condition
evaluates to false, control passes to the statement following the do...while
.do...while
In the following example, the do...while
loop iterates at least once and reiterates until i
is no longer less than 5.
var i = 0; do { i += 1; console.log(i); } while (i < 5);
Created by Mozilla Contributors, license: CC-BY-SA 2.5