Statements & control flow
A statement is a step the program takes. This family is how control
moves: if / elif / else choose a branch, while repeats while a
condition holds, for walks a collection or a range, switch selects an
arm by value, and match exhausts the variants of a union.
then lets a branch be a single statement instead of a block — a common
way to write an early return. guard groups those checks at the top of
a function. return leaves a function; break and continue leave or
skip a loop; pass is the explicit empty body. assert and panic are
diagnostics. require and reject are the one-line throws; they need an
error channel, which lives on the error channel page.
main {
let i32 score ← 85
if score ≥ 90 {
print "A"
}
elif score ≥ 80 {
print "B"
}
else {
print "C"
}
let list<i32> nums ← [1, 2, 3]
for from nums let item {
print item
}
mut i32 n ← 0
while n ≺ 2 {
n ← n + 1
}
print n
}switch picks the first matching value. default is the fallback:
fn describe(i32 value) → string {
switch value {
case 1 { return "one" }
case 2 { return "two" }
default { return "many" }
}
}
main {
print describe(2)
}Return to the grammar overview.
Terms#
These are the words you write in this part of the language. Each links to its page. The second column names the grammar rule the word belongs to.
| Term | Grammar rule |
|---|---|
if | si_stmt |
elif | si_tail |
else | secus_clause |
while | dum_stmt |
ref, for, let, mut | itera_stmt |
range, and, from | itera_clause |
and | itera_binding |
at | apud_clause |
switch | elige_stmt |
case | casu_elige_clause |
default | ceterum_clause |
match, all | discerne_stmt |
and | discriminants |
case | casu_variant_clause |
guard | custodi_stmt |
if | si_guard_clause |
from, let, mut | ex_stmt |
as | extract_field |
rest | ceteri_field |
return | redde_stmt |
return_await | reddet_stmt |
await | tacebit_stmt |
yield | cede_stmt |
break | rumpe_stmt |
continue | perge_stmt |
pass | tacet_stmt |
assert, panic | adfirma_stmt |
throw, require | requirit_stmt |
throw, reject | reice_stmt |
warn, write, debug | nota_stmt |
while, do | fac_stmt |
all | fac_modifier |
Formal grammar#
The rules for this part of the language are the parser's own definition of it. They are written for models and tools, so this page does not repeat them; the full list is at every production.