Do While Loop

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

Demo


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 80 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.

❤👩‍💻🕹