Possible Duplicates:
for loop optimization
for-loop optimization – needed or not?
e.g.
int maxloop = complicated();
for (int i=0;i<maxloop;i++){}
or
for (int i=0;i<complicated();i++){}
Is the compiler smart enough to optimize it?
what about while?
No, the compiler is not smart enough to optimize it because it cannot guarantee that
complicated()doesn’t do anything different if it is run multiple times.