Loops and iterations
Envision relies first and foremost on its relational algebra features to iterate over large collections of data: every operation in Envision is applied to all the lines of a table. Such vectorized operations are well-optimized both in terms of speed and memory usage, and should be used whenever possible.
For cases when a computation cannot be expressed using the vectorized operations alone, Envision provides several advanced iteration features:
for
blocks are the standard way of iterating over all lines of a table, and executing a block of code for every line. Not all operations are allowed inside the block.each
blocks are a more complex alternative tofor
blocks that can take advantage of the relations between tables. Not all operations are allowed inside the block.loop
blocks have little to no limitations on what operations are allowed inside the block, but are limited to 10 iterations.
The design of Envision enforces a constraint on all forms of iteration: any loop, no matter how complex, must have a maximum number of iterations. This excludes loops that run until a condition becomes false (the while
loops of many languages).
Other language features, such as montercarlo
and autodiff
, also rely on iteration to execute their body several times.