title: Javascript and html: window updates before document
body: <p>As you can see in the code below, I want to run the loop 3 times and in each run write a line to the document. However, when I open the page, the alert message pops up 3 times and only then I see the new words on the page.</p>
  
  <p>Why is it happening? Is there a way to update the document while still in the loop?<br>
  I'm guessing it's related to the "window" and "document", but I'm not quite sure how they work... Anyway, thanks in advance!</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;script&gt;
  
          var words = ["please", "print", "me!"]
  
          for (word of words) {
              alert("don't mind me!");
              document.write(word + "&lt;/br&gt;")
          }
  
      &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/IrzQS.gif]" alt="gif of the page"></p>