If you have code within a loop tha uses non-varying variables:
for(i = 0; i < 100; i++)
{
total = i + x + y;
printf(\"%d\", total);
} //end for
as you can see, x and y are not variable within the loop and so it is much more efficient to code the loop as follows:
total = x + y;
for (i = 0; i < 100; i++)
{
total += i;
} this is because the loop does one less addition on each loop cycle.
Author : Iain
0 nhận xét:
Post a Comment