With the inverse for loop, you're only doing one variable lookup per iteration:
$w > 0 // <-- one lookup to the $w variable
$w < $counter // <-- two lookups, one for $w, one for $counter
This is why the inverse is slightly faster. Also, a while loop has only one operation per iteration:
$w < $counter // <-- one operation while loop
$w < $counter ; $w++ // <-- two operation for loop
Of course, you have that extra operation inside the loop's code block, but I'm not sure exactly why that's faster (maybe someone can fill in the blank there). You'll notice the time difference is minimal, because these operations are still very fast. Such micro-optimisations are most effective on very large loops.
Andy E
2010-04-09 23:39:46