JS Do While Loop - ashish9342/FreeCodeCamp GitHub Wiki

JavaScript do...while Loop

The do...while loop is closely related to while loop. In the do while loop, the condition is checked at the end of the loop.

Here is the syntax for do...while loop:

Syntax:

 do {

   *Statement(s);*

}while (*condition*);

statement(s): A statement that is executed at least once before the condition or Boolean expression is evaluated and is re-executed each time the condition evaluates to true.

condition: Here, a condition is a Boolean expression. If Boolean expression evaluates to true, the statement is executed again. When Boolean expression evaluates to false, the loops ends.

Example:

var i = 0;
do {
  i = i + 1;
  console.log(i);
} while (i < 5);
Output:
1
2
3
4
5

source: do...while

⚠️ **GitHub.com Fallback** ⚠️