POV-Ray : Newsgroups : povray.text.tutorials : Summing over indices of an array : Re: Summing over indices of an array Server Time
20 Sep 2021 06:27:43 EDT (-0400)
  Re: Summing over indices of an array  
From: Mike Williams
Date: 22 Jan 2005 03:06:26
Message: <l3taCGA5lg8BFw4s@econym.demon.co.uk>
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 2003-2021 Persistence of Vision Raytracer Pty. Ltd.