POV-Ray : Newsgroups : povray.text.tutorials : Summing over indices of an array : Re: Summing over indices of an array Server Time: 24 Jul 2008 08:09:08 GMT
  Re: Summing over indices of an array  
From: Mike Williams
Date: 22 Jan 2005 08:06:26
Wasn't it Max Ulbrich who wrote:
>Hi,
>
>I just trying to get started with Povray and try to sum elements of an 
>array.
>If I use elem[0]+elem[1]+elem[2]+... it works fine.
>If I try sum(i,1,n,elem[i]) I get an error.

sum() only works inside a function{} and array[] references don't work
inside a function{}. So, whether you're trying to do the sum inside or
outside a function{} it's not going to work.

I think you have to use a loop:

#declare i=1;
#declare Sum=0;
#while (i<=n)
  #declare Sum = Sum + elem[i];
  #declare i=i+1;
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

Copyright 1991-2004 POV-Team™