← Back to AILP Home

Loop Constructs Cookbook

This subsection is the canonical v0.38.8 guide for Nitpick's loop family and the control-flow that steers it. It supersedes the older, scattered loop notes in guide/control_flow/ and the loop fragments embedded in guide/basics/, where those pages are shorter or stale.

The v0.38.x cycle locked the shipped behavior of every loop surface:

Chapters

  1. Basics — the loop mental model, when to reach for each form, and the shared block/scope rules.
  2. while — condition-driven loops, re-evaluation, and parameter mutation inside the condition.
  3. loop — counted loop(start, limit, step), the $ index, and step direction / zero-step failsafe.
  4. tilltill(limit, step), the $ running value, and its desugaring to loop.
  5. for-infor x in <range> and for x in <array> iteration.
  6. break and continue — bare control, the back-edge, and how continue differs across forms.
  7. Labeled control — loop labels, break(label) / continue(label), and targeting an outer level.
  8. Nested loops — nesting, innermost-by-default targeting, and multi-level escape patterns.
  9. Invariants and contracts — loop invariant with break/continue, entry vs back-edge obligations, and the --verify-contracts / --debug-contracts flags.

Quick mental model

Validation snapshot (v0.38.8)