|
![](/i/fill.gif) |
"Ken" <tyl### [at] pacbell net> wrote in message
news:38C93DE2.2E56417B@pacbell.net...
>
> this stores the current value of i into the array at each position (so
> MyArray[5] = 5) to get them out, simply do something like the
following
>
> #declare i = 0;
> #declare Sum = 0;
> #while (i < num)
> #declare Sum = Sum + MyArray[i];
> #declare i = i + 1;
> #end
Hmm, I don't get it:
If "MyArray[i]" always has the value "i", why then use the array in the
first place? Simply substituting "i" has the same effect, hasn't it?
after all: "MyArray[i]" equals "i" - they are equivalent, so you can
rewrite your code without the array:
#declare i = 0;
#declare Sum = 0;
#while (i < num)
#declare Sum = Sum + i;
#declare i = i + 1;
#end
(I am assuming that this is just a trivial example, because if you
really were after the sum, you wouldn't use a loop like that but would
use a mathematical formula instead, wouldn't you? Sum = num/2 * (num+1))
Johannes.
Post a reply to this message
|
![](/i/fill.gif) |