JavaScript Do While Loop Example

JavaScript do...while loop check condition and execute a block of code for a specify number of times, until the condition become false.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript do...while loop</title>
</head>
<body>
<pre>  <!-- Use pre element for work document.writeln() method -->
<script>
    number = 1;
    do {
        document.writeln(number + " times");
        number++;
    } while (number <= 10) 
    document.writeln("Total " + (number - 1) + " times loop repeat");
</script>
</pre>
</body>
</html>

Run it...   »

Example Result