...

# loop

The loop keyword offers a mechanism to repeat a short series of Envision operations. The maximal number of iterations is 10. This low maximum is intentional as arbitrary loops introduce problems that are better solved through the other constructs of the Envision language.

## loop (n : number), code block

The loop keyword takes a single argument which must be an integer literal between 1 and 10 (inclusive).

a = 1
loop 3
b = a + 1
a = 2 * b
show summary "" with a, b // 22, 11


## loop (n : number) in (low : number) .. (high : number), code block

The loop keyword defines an iteration variable over a segment of integer values. The boundaries are inclusive.

s = 0
loop n in 11 .. 15
s = s + n
show summary "" with s // 65


## loop (n : number) in sequence, code block

The loop keyword defines an iteration variable over an explicit list of values.

msg = ""
loop n in "h", "e", "l", "l", "o"
msg = concat(msg, n)
show summary "" with msg // 'hello'


## loop (n : number) partitioned, code block

The loop .. partitioned block partitions a table in the specified number of blocks. This syntax is intended for the parallelization of the Envision flow when processing very large tables, typically beyond 1 billion lines.

table T = extend.range(123)

T.N2 = 0
loop 10 partitioned table T
T.N2 = T.N ^ 2

show table "" with T.N, T.N2


This syntax is a syntactic sugar over the loop n in 1 .. 10 syntax.

The effect of the partitioned keyword is almost equivalent to:

table T = extend.range(123)

T.N2 = 0
T.Rank__ = rank() scan T.N
size__ = count(T.*)
T.Part__ = 1 + floor((T.Rank__ - 1) / size__) * 10
loop n in 1 .. 10
where T.Part__ == n
T.N2 = T.N ^ 2

show table "" with T.N, T.N2


However, the syntax takes care of avoiding the rounding errors which could impact floor((T.Rank__ - 1) / size__).

User Contributed Notes
0 notes + add a note