# iterate()

Here’s how to use iterate() function.

## A .iterate()

Description:

Perform interative 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.

Parameters:

 A A sequence/record sequence x An expression a The initial value c A boolean expression

Options:

 @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 functions:

## ch.iterate()

Description:

Perform interative 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.

Parameters:

 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] 2 =channel() 3 =channel() 4 =A2.iterate(~*2) 5 =A3.iterate(~~*2,3) 6 =A1.push(A2,A3) 7 =A2.result() 4444 8 =A3.result() 96 9 =[100,200,800,2000] 10 =channel() 11 =A10.iterate(~~*3,10,~>250) 12 =A9.push(A10) 13 =A10.result() 90

## cs.iterate()

Description:

Perform interative 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.

Parameters:

 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.

Parameters:

 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 functions: