JavaScript do-while Loop and It's Example


do-while loop

The do..while loop is similar to the while loop except that the condition check happens at the end of the loop.

This means that the loop will always be executed at least once, even if the condition is false.

Syntax:

do
{
  StatementI(s) to be executed;
}        
while(expression);

Example :


Result :


  loop = 0
  loop = 1
  loop = 2
  loop = 3
  loop = 4
  loop = 5