title: Why doesn't print output anything on each iteration of a loop when I use sleep?
body: <p>Today in my college a teacher asked me a question. He wrote this code on the paper and said 
  "What will be the output of this code?"</p>
  
  <pre><code>use warnings;
  
  for (1 .. 20)
  {
      print ".";
  }
  </code></pre>
  
  <p>I found it easy and said that it will loop 20 times and at each iteration it will print a dot (.) and hence total 20 dots will be the output.</p>
  
  <p>He said you are right and then he made some changes in the code. The code was:</p>
  
  <pre><code>use warnings;
  
  for (1 .. 20)
  {
      print ".";
      sleep 1;
  }
  </code></pre>
  
  <p>He said the what will be the output now? I didn't know about the sleep function, I guessed that at each iteration it will print the dot (.) and then it will wait for 1 second (because of the sleep function) and then again it will iterate and then again it will print (.) then it will wait for 1 second and so on...</p>
  
  <p>The teacher told me to check it at home. I tried it at home and I came to know that the second code waits for 20 seconds and then it prints all dots (20 dots) at once. I want to know how this happened? Why isn't the dot (.) is getting print on each iteration?</p>