POV-Ray : Newsgroups : povray.general : Array? : Re: Array? Server Time
10 Aug 2024 03:19:17 EDT (-0400)
  Re: Array?  
From: Johannes Hubert
Date: 12 Mar 2000 19:01:07
Message: <38cc2fc3@news.povray.org>
"Ken" <tyl### [at] pacbellnet> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.