each
each, keyword
The each
keyword offers an iteration mechanism against an observation table. Iterations are not ordered.
Example:
table Obs = with
[| as N |]
[| 1 |]
[| 2 |]
[| 3 |]
Obs.Cpy = each Obs
cpy = Obs.N + 1
return cpy
show table "" a1b3 with Obs.N, Obs.Cpy
each .. scan , keyword
The each .. scan
keywords offer an iteration mechanism against an observation table. Iterations are ordered based on the argument passed to scan
.
Example:
table Obs = with
[| date(2021, 1, 1) as Date, 13 as Quantity |]
[| date(2021, 2, 1) , 11 |]
[| date(2021, 3, 1) , 17 |]
[| date(2021, 4, 1) , 18 |]
[| date(2021, 5, 1) , 16 |]
Best = 0
Obs.BestSoFar = each Obs scan Obs.Date
keep Best
NewBest = max(Best, Obs.Quantity)
Best = NewBest
return NewBest
show table "" a1b4 with Obs.Date, Obs.BestSoFar
each .. in .. , keyword
The each X in T.X
offers a simple iteration mechanism over the values of a specified vector. Unlike the other each
blocks, there is no diagram, no observation table, etc.
This mechanism allows to cross a table with itself, as illustrated by:
table T = extend.range(5)
T.S = each N in T.N
return N * sum(T.N) when (N < T.N)
show table "" a1b5 with T.N, T.S