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
ifremains an expression-oriented form for straightforward branching.whileandforare part of the supported teaching surface for loops.matchis 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, andself-hosted/parser/patterns.siodefine most of the relevant syntax handling.self-hosted/check/patterns.sio,self-hosted/check/exhaustiveness.sio, andself-hosted/check/pat_decision.sioare 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.