title: How could I write into a document instantly in loop(javascript)?
body: <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>while(something)
  {
  setTimeout(function()
  {
  var btn = document.createElement("P");
         var t = document.createTextNode(str);  //str-&gt;string variable
      btn.appendChild(t);
         document.body.appendChild(btn);
      },1000);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>My program supposed to write out the str variable every time immediately after the delay but it only writes it out at the end.
  Any solution to make it instant?</p>