Re: Mathematical models for loop calculations



On Wed, 26 Sep 2007 13:46:20 +0000, Richard Heathfield wrote:

i = 0,
b = 2,
c = 2,
d = 2,
e = 2;

while( i < 10 ) {
a = a + 1;
b = b + b;
c = c * c;
d = d + e;
e = e + 1;
i++;
}


Overall:

a += I;
b = pow(2, I);
c = pow(2, pow(2, I));
d = I * (I + 1) /2 + 1;
e += I;

I just see that these cases work since most of the variables
were assigned the value '2'. If you change them to '3', some
formulas like the one for 'b' will not work any more.
Are there also any general formulas that depend on the current
value of the identifiers before entering the loop?

.