Ivo wrote:
[...]
Does it? Try this:
var s = -1;
alert( new Boolean(s) ); // true !
Besides, the while loop never gets to -1 because it ends when i becomes 0
(which does evaluate to false).
Ooops, good point.
The logic may not be immediately clear, but do() loops are by far the
fastest loops that javascript has to offer. Next come while() loops, and
for() loops, when compared, are really just *slow*. (It may not make much
difference when dealing with only a few radio buttons.)
The point was not speed of execution, it was how easy the code is
to read and maintain. I was just posing my point of view, not
taking exception to RobB's (excellent) code.
For a comparison, see
< http://www.websiteoptimization.com/speed/10/10-2.html >
although there appears to a bug in the code on that page. They also explain
Yes, there is a form with a name "testLoop" and a function called
"testLoop".
The difference between 'for' and 'do/while' on my ancient laptop
was about 3% (861 vs 831) but yes, do/while was faster. It was
revealing to see that simply reversing the direction of count -
down rather than up - produces a huge performance gain (861 to
381 - a 55% reduction).
Reverse 2 was faster than reverse 3.
So I guess wherever performance is an issue, reversed do/while's
the go. :-x
--
Rob