ScanSkill

do...while

The do…while statement creates a loop that executes as long as the condition is true.

Syntax

do {
  // Statements
} while(condition);

In the do...while statement, The do keyword creates a starting point for the loop, as well as a place for keeping statements that are wrapped inside parenthesis. The while keyword contains the condition for the loop to run.

Example

let i = 0;

do {
  i++;;
  console.log(i);
} while (i < 5);
/* Prints:
1
2
3
4
5
*/

The do…while checking the condition after executing the statement, it is unique from other loops as all the other loops check the condition before running the internal statement. Making this loop run statement 1 time more than other looping statements.