elige
Translation status: العربية reader-locale proof. Code fences render through the ar pipeline; prose is canonical Latin.
Starts a value-based branch statement.
Aliases: switch, choose
Syntax: elige <expression> <block>
Category#
control-flow
Related#
Examples#
radix/corpus/elige/elige.fab (canonical · keyword)#
Starts a value-based branch statement.
# =============================================================================
# elige — Starts a value-based branch statement.
# =============================================================================
#
# What this teaches:
# • Value-based branching — `elige <expr> { casu <value> { ... } }` dispatches on a value (switch/choose pattern).
# • Multiple types — `elige` works with textus, numerus, and other comparable types.
# • Multi-statement cases — each `casu` block can have multiple statements.
#
# Common mistakes:
# • Non-exhaustive `elige` without `ceterum` — unmatched values silently produce no output; use `ceterum` for a default branch or cover all possible values.
#
# See also: casu, ceterum
# =============================================================================
# elige — switch on a value
#
# elige <expr> {
# casu <value> { <body> }
# ceterum { <body> }
# }
#
# GRAMMAR:
# eligeStmt :← 'elige' expr '{' casuClause* '}'
#
# EXPECTED OUTPUT:
# elige.expected
main {
# Text matching
const _ condicio ← "agens"
switch condicio {
case "pendens" {
print "exspectat..."
}
case "agens" {
print "currit"
}
case "perfectum" {
print "perfectum"
}
}
# Numerus matching
const _ codex ← 200
switch codex {
case 200 {
print "Recte"
}
case 404 {
print "non inventum"
}
case 500 {
print "error ministri"
}
}
# Multiple statements per case
const _ modus ← "opera"
switch modus {
case "labor" {
print "modus laboris"
print "verba multa"
}
case "opera" {
print "modus operis"
print "opera parata"
}
}
}Expected output:
currit
Recte
modus operis
opera parata