[Thread Prev][Thread Next][Index]

Re: accumulate a number



Hi Dongxiao,

You can accumulate using either DEFINE SYMBOL and the symbol syntax of
($symbol_name) or immediate mode evaluation of a variable defined with
LET as illustrated below. As a general rule I would suggest first to see
if there is a way to solve the problem without using an accumulated
variable, though.

Example:

yes? let a = 1
yes? repeat/i=1:3 (let a=`a`+1; say `a`)
!-> REPEAT: I=1
 !-> DEFINE VARIABLE a=1+1
 !-> MESSAGE/CONTINUE 2
2
!-> REPEAT: I=2
 !-> DEFINE VARIABLE a=2+1
 !-> MESSAGE/CONTINUE 3
3
!-> REPEAT: I=3
 !-> DEFINE VARIABLE a=3+1
 !-> MESSAGE/CONTINUE 4
4
yes? cancel mode verify
yes? repeat/i=1:3 (let a=`a`+1; say `a`)
5
6
7

    - steve

=====================================

Dongxiao Zhang wrote:

> Hi all,
>
> Is there a way to accumulate a number through the repeat loop?
>
> In Fortran, we can do it by: do i=1:10
>                                A=A+1
>                              enddo
>
> But in Ferret, repeat/t=`t1`:`t2`:`dt` (let A=A+1) is illegal.
>
> Any suggestions. Thanx.
>
> Dongxiao
>
> --------------------------------------------------------------------
>  Dr. Dongxiao Zhang
>  NOAA/PMEL Bld#3
>  7600 Sand Point Way NE
>  Seattle, WA 98115-0070
>  Phone  : (206)526-4184
> --------------------------------------------------------------------

--
Steve Hankin
NOAA/PMEL, 7600 Sand Point Way NE, Seattle, WA 98115-0070
ph. (206) 526-6080 -- FAX (206) 526-6744




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement