Control Flow

Conditionals, loops, and match expressions.

Control Flow

Control flow is one of the safest parts of the language to document, but it still benefits from conservative examples. This page focuses on the forms that remain useful in onboarding and in reading current fixtures.

Current contract

  • if remains an expression-oriented form for straightforward branching.
  • while and for are part of the supported teaching surface for loops.
  • match is important both for branching and for understanding how exhaustiveness work evolves in the checker.

Representative control flow

let max = if a > b { a } else { b }

while count < 3 {
    count = count + 1
}

match state {
    0 => println("cold")
    _ => println("hot")
}

Where to inspect behavior

  • self-hosted/parser/exprs.sio, self-hosted/parser/stmts.sio, and self-hosted/parser/patterns.sio define most of the relevant syntax handling.
  • self-hosted/check/patterns.sio, self-hosted/check/exhaustiveness.sio, and self-hosted/check/pat_decision.sio are the places to inspect match-related semantics.
  • tests/run-pass/ is still the right place to look for current examples that the compiler accepts today.

Practical guidance

  • Prefer simple branching and matching examples when writing public docs.
  • If you document advanced pattern matching behavior, verify it against the current checker instead of assuming the design note and artifact always match.
  • Treat the spec as the larger intent and the fixtures as the best proof of current behavior.