[Thread Prev][Thread Next][Index]

Re: recursive definitions





On Tue, 24 Oct 2000, 'Jeff Polton' wrote:

> Dear Ferreteers,
> 	I'm struggling trying to define a variable which is the sum of a
> number of others:
> 
> potemp = temp1 + temp2 + temp3 + ... + temp20
> 
> Ferret doesn't like recursive loops:
> REPEAT/K=1:20 (potemp = temp`K` + potemp)
> 

Jeff,

This should work

let var1=temp1
repeat/k=2:20 (let var`k` = var`k-1` + temp`k`)


var20 will contain the complete sum.

To cut down on the number of intermediate variables you could define

let var2=temp1+temp2
repeat/k=4:20:2 (let var`k` = var`k-2` + temp`k` + temp`k-1`)

and so on.

Cheers,
Russ Fiedler



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement