Control Flow
Conditionals, while loops, through modes, break/continue, and loop invariants.
Conditionals
Parentheses around the condition are optional. A block always uses braces; there is no single-statement form.
While loops
while (condition) { ... } is also accepted. The condition is evaluated before each iteration; any truthy value continues the loop.
through loops
through is the canonical iteration construct. It takes an optional iterator name, an iterable, an optional arrow, and one of five modes.
| Mode | Result | Use |
|---|---|---|
loop | none | side effects only |
collect | array | map each element to a new value |
filter | array | keep elements for which the body is true |
every | Bool | true when the body is true for all elements |
unique | array | keep the first occurrence of each value |
A range (0..9) is inclusive on both ends. Iterating an Array or Map walks its elements; map order is unspecified.
SIMD-friendly loops
through loops are eligible for SIMD lowering when the body is a simple typed-array kernel. The emitter adds __restrict__ pointer annotations, hoists invariant field loads, and checks a relaxed shape-safety condition. You do not write intrinsics; use typed arrays and straightforward indexing:
The vectorizer is a performance path, not a semantic change. Keep aliasing out of the loop body if you want the compiler to take it.
Break and continue
break leaves the innermost loop; continue advances to the next iteration. Inside collect / filter, continue skips the current result and break terminates the derivation early.
Loop + region caveat. A break or continue from a loop nested inside a region triggers region-unwind emission for every open region. Keep loops outside regions when the loop can exit early, or use a while loop with explicit state, until the unwind path is tightened.
Loop invariants
@invariant(expr) prefixes a while or through ... -> loop body. The expression is checked after every normal iteration, following the "invariant holds after each step" form.
The same ruleset { contracts = ... } mode that controls requires / ensures controls invariants:
A violation halts with VNE-111. continue currently jumps to the next iteration before the check runs; restructure the body if that path matters.
Nesting and early exits
There are no labeled loops. To exit multiple levels, carry a flag or move the search into a function and return.