Do While Loop

showing how to use a do while loop, i don't use these ones very often usually just a for loop.

function do_while_loop() {
  var ourArray = [];
  var i = 0;
  var max = 20;
  var out = "";
  do {
    ourArray.push(i);
    i++;
    out += i + ",";
  } while (i < max);

  var result_html = document.getElementById("result");
  result_html.innerHTML = out;
}

HTML

<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='do_while_loop();' class='btn btn-primary'>Run do_while_loop()</button>

Result

..

Other Items in javascript
Page Views

This page has been viewed 332 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
All of humanity's problems stem from man's inability to sit quietly in a room alone, wrote Blaise Pascal.
Unknown