for is Coalton’s built-in imperative loop form.
Syntax
(for (⟨binding-clause⟩...)
[:returns ⟨expr⟩]
[{:while | :until | :repeat} ⟨expr⟩]
⟨body⟩...)
;; ⟨binding-clause⟩ := (⟨var⟩ ⟨init-expr⟩ ⟨step-expr⟩)
Semantics
- Initializers are established before the first iteration.
- Step expressions are evaluated in parallel from the previous iteration’s bindings.
:whileloops while the condition is true.:untilloops until the condition is true.:repeatloops a certain fixed number of times.:returnsspecifies what to return when the loop exits, either normally or by(break).- No
:returnsmeans the loop unifies withVoid. - Use
for*when later steps should see earlier updated values.
Example
(for ((i 0 (1+ i)))
:until (>= i 10)
(show i))