This may be a stupid question, but how does the efficiency of a while loop compare to that of a for loop? I\'ve always been taught that if you can use a for loop,
I think you're drawing the wrong conclusion from the advice you've been given.
The reason (in this instance at least) to prefer the for construct over the while has nothing to do with efficiency; it's all about writing code that expresses your intentions in a clear and easy to understand manner.
The for places the initial condition, increment, and exit condition all in one place, making it easier to understand. The while loop spreads them around. For example, in your sample, what is the initial value of i? -oh, you forgot to specify it? --that's the point.