<p>I have stumbled into several methods of looping in JavaScript, what I like the most is:</p>

<pre><code>for(var i = 0; i &lt; a.length; i++){
    var element = a[i];
}
</code></pre>

<p>But as tested here (<a href="http://www.robertnyman.com/2008/04/11/javascript-loop-performance/" rel="noreferrer">http://www.robertnyman.com/2008/04/11/javascript-loop-performance/</a>), it should probably be written so that the length is only calculated once. </p>

<p>In jQuery there is a .each that you can stick a function. I like this a little better, because I don't have to type the array twice, like in the above solution. </p>

<p>If JavaScript supported macros it would be a piece of cake to roll your own, but sadly it does not. </p>

<p>So what do you guys use?</p>

You could just always use a while loop, and compute the array limit before hand.
```
```
Var max = a.length-1;
var i = 0;

while(i <= max)
{
var element = a[i];
i++;
}
```
```