iterate()

Read(2668) Label: iterate,

Here’s how to use iterate() functions.

A.it erate()

Description:

Perform iterative loop on a record sequence and return the result of the last calculation of a given expression.

Syntax:

A.iterate(x,a,c)

Note:

The function loops through members of record sequence A to calculate expression x and returns the result of the last calculation of x. ~~ represents the previous value of x. Parameter a is the default initial value for each calculation, whose absence indicates a null initial value. Exit the loop once the result of expression c is true.

Parameter:

A

A sequence/record sequence

x

An expression

a

The initial value

c

A Boolean expression

Option:

@a

Return the results of calculating the expression over every member

Return value:

Result of expression x

Example:

 

A

 

1

[2,222,22,122,2222]

 

2

=A1.iterate(~*2)

4444

3

=A1.iterate@a(~*2)

[4,444,44,244,4444]

4

=A1.iterate(~~*2,3)

96

5

=A1.iterate(~~*2,5,~>500)

80

6

=demo.query("select * from SALES")

 

7

=A6.derive(A6.(AMOUNT).iterate(~~*2,5,~>20000):Cumulation)

Related function:

iterate()

ch.iterate()

Description:

Perform iterative loop on record sequences in a channel and return the result of the last calculation of a given expression.

Syntax:

ch.iterate(x,a,c)

Note:

The function loops through record sequences in channel ch to calculate expression x and returns the result of the last calculation of x. ~~ represents the previous value of x. Parameter a is the default initial value for each calculation, whose absence indicates a null initial value. Exit the loop once the result of expression c is true.

Parameter:

ch

A channel

x

An expression

a

Initial value

c

An expression returns true/false

Return value:

Result of expression x

Example:

 

A

 

1

=[2,222,22,122,2222].cursor()

 

2

=channel()

 

3

=channel()

 

4

=A2.iterate(~*2)

 

5

=A3.iterate(~~*2,3)

 

6

=A1.push(A2,A3)

 

7

=A1.fetch()

 

8

=A2.result()

4444

9

=A3.result()

96

10

=[100,200,800,2000].cursor()

 

11

=channel()

 

12

=A11.iterate(~~*3,10,~>250)

 

13

=A10.push(A11)

 

14

=A10.fetch()

 

15

=A11.result()

90

cs.iterate()

Description:

Perform iterative loop on record sequences in a cursor and return the result of the last calculation of a given expression.

Syntax:

cs.iterate(x,a,c)

Note:

The function loops through record sequences in cursor cs to calculate expression x and returns the result of the last calculation of x. ~~ represents the previous value of x. Parameter a is the default initial value for each calculation, whose absence indicates a null initial value. Exit the loop once the result of expression c is true.

Parameter:

cs

A cursor

x

An expression

a

Initial value

c

An expression returns true/false

Return value:

Result of expression x

Example:

 

A

 

1

=[2,222,22,122,2222].cursor()

 

2

=A1.iterate(~*2)

4444

3

=[2,222,22,122,2222].cursor().iterate(~~*2,3)

96

4

=[2,222,22,122,2222].cursor().iterate(~~*2,5,~>500)

80

5

=demo.cursor("select * from SALES")

 

6

=A5.(AMOUNT).iterate(~~*2,5,~>20000)

40

iterate ()

Description:

An iterative loop for calculating an expression.

Syntax:

iterate(x,a;Gi,…)

Note:

The function performs an interative loop to compute expression x – which contains a ~~, and returns the result. Each time when the value of field Gi changes, the value of ~~ becomes a. The parameter Gi can be omitted. When parameter a isn’t supplied, its value is null.

Parameter:

x

An expression containing ~~

a

Initial value

Gi

Field name

Return value:

Value of the given expression

Example:

 

A

 

1

=demo.query("select top 7 * from SCORES ")

 

2

=A1.groups(CLASS:Class,STUDENTID:StudentID;iterate(~~*2): Score1)

3

=A1.groups(CLASS:Class,STUDENTID:StudentID;iterate(~~*2,10): Score1)

4

=A1.derive(iterate(~~*2,10;STUDENTID):F1)

Related function:

A.iterate()