While Loop Demo: Print 0 to 5

This keeps the original demo result while using DOM output instead of document.write().

Complete Working Source Top ↑

<!doctype html>
<class="text-primary">html lang="en">
<class="text-primary">head>
<class="text-primary">meta charset="utf-8">
<class="text-primary">meta name="viewport" content="width=device-width, initial-scale=1">
<class="text-primary">title>While Loop Demo: 0 to 5</class="text-primary">title>
<class="text-primary">style>#output { white-space: pre-line; }</class="text-primary">style>
</class="text-primary">head>
<class="text-primary">body>
<class="text-primary">div id="output" aria-live="polite"></class="text-primary">div>
<class="text-primary">script>
const output = document.getElementById("output");
let text = "";
let i = 0;

while (i <= 5) {
  text += `${i}\n`;
  i += 1;
}

output.textContent = text;
</class="text-primary">script>
</class="text-primary">body>
</class="text-primary">html>

Return to tutorial on While loop




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer