Can I set multiple window.setTimeout events in a for loop?
<p>Here's a piece of code I copied from<br>
<a href="http://www.schillmania.com/content/projects/javascript-animation-1/demo/" rel="nofollow">http://www.schillmania.com/content/projects/javascript-animation-1/demo/</a><br>
Very simple JS animation:</p>

<pre><code>function doMove() {
  foo.style.left = parseInt(foo.style.left)+1+'px';
  setTimeout(doMove,20); 
}
</code></pre>

<p>This works fine. However if I change it like this:</p>

<pre><code>function doMove() {
   for (var i=0; i&lt;1000; i++) {
       setTimeout(function(){foo.style.left = parseInt(foo.style.left)+1+'px';},20*i);
   }
}
</code></pre>

<p>Consequently there's no animation at all.
As far as I know JS engine pushes those events into the queue whenever setTimeout is called. So I just don't understand why this doesn't work.</p>
