JavaScript Loops : Do-While Loop

The do...while loop is a variant of the while loop. It 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. The Syntax of do...while loop is as follows :
 do {
   code to be executed
 } while (condition);
For example :
<!DOCTYPE html>
<html>
<head>
  <title>Do...While Loop</title>
</head>
<body>
  <p id="demo"></p>
  <script>
    var x = 2, count = 0;
    var text = '';
    do {
      text = text + x*count + '<br/>';
      count++;
    } while(count <= 10);

    document.getElementById("demo").innerHTML = text;
  </script>
</body>
</html>
Output :



Next Topic :