loop
loop
#
cg.while_repeat — collect a block into a ProcedureWhile.
The block is the loop body; the yielded folder is a fresh array_path
element that each iteration appends and caches into. Do-while semantics: the body
runs, then condition is evaluated, and while it is true (and max_iterations
is not reached) the body runs again.
condition and array_path are built by the caller (before the with), so
they are recorded in the enclosing context and caught by the ProcedureWhile.
The yielded folder (a PathAppend on array_path) is built inside the
block, so the body's per-iteration nodes descend from it and reduce to the loop
body. On the device the body and condition are cloned per iteration; the
loop-invariant array_path and max_iterations are referenced once.
DEFAULT_MAX_ITERATIONS = 1000
module-attribute
#
Iteration cap when while_repeat is called without max_iterations.
The condition drives normal termination; this only bounds a runaway loop.
WhileContext
#
Bases: ProcedureContext
Reduce a block's roots to the body of a ProcedureWhile.
Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/loop.py
__init__(condition, array_path, max_iterations)
#
Reduce the block into the loop body appending into array_path.
Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/loop.py
while_repeat(condition, array_path, *, max_iterations=DEFAULT_MAX_ITERATIONS)
#
Repeat the with block, appending one array_path element per iteration.
Yields the freshly appended element's Path (folder); cache into it with
|= / &= like any path. Do-while: the body runs, then condition is
evaluated, and while it is true (and max_iterations is not reached) the body
runs again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
Procedure[Bool]
|
Boolean procedure evaluated after each iteration; the loop
continues while it is true. Built before the block, so it is a
loop-level decision (e.g. |
required |
array_path
|
Procedure[Path]
|
The |
required |
max_iterations
|
Procedure[Number] | int
|
Hard iteration cap (a safety bound; the condition drives
normal termination). A raw |
DEFAULT_MAX_ITERATIONS
|