Originally posted by satya sahu:
Hi,
I have two for loops,
for(int i = 0; i < 10000, i++)
and
for(int i = 10000, i>=0; i--)
Which one has more iterations in and why?
Note the slight change I have made to that quote.
The correct answer to your actual question is "don't know, don't care." You program for correctness and if you want to iterate one direction you use one loop and for the other direction you use the other, conveniently ignoring the fact that one of those loops might (in a very sensitive situation) cause an Exception to be thrown. You make performance your lowest priority.
There was a
thread about 2 years ago about "is repeated i++ faster than repeated i--" which you might find in a search; I tried out a simple application to
test that suggestion and I can't remember which was faster. But I can remember it was only slightly faster and occasionally the other operation was faster. So not only is performance a low priority, it is also unpredictable and variable.
Let's see what everybody else says, now!