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.


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

Run it...   »

Example Result