case
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Introduces a branch inside an switch or match statement.
Aliases: case
Syntax: case <expression> <block>
Category#
control-flow
Related#
Examples#
radix/corpus/casu/casu.fab (canonical · keyword)#
Introduces a branch inside an switch or match statement.
# =============================================================================
# case — Introduces a branch inside an switch or match statement.
# =============================================================================
#
# What this teaches:
# • Pattern matching arms — `case <expression> <block>` defines a branch in
# an `switch` match expression
# • Default fallback — `default` provides the catch-all branch when no
# `case` pattern matches
#
# Common mistakes:
# • non-exhaustive match without a `default` catchall — every `switch` or `match` must cover all possibilities or add a `default` arm
#
# See also: switch, match
# =============================================================================
# case — branch arm in switch or match
#
# GRAMMAR:
# casuClause :← 'case' expr block
#
# EXPECTED OUTPUT:
# Scalar stdout smoke (see body).
#
# BACKEND:
# Cross-ref: switch/elige.fab, match/discerne.fab.
#
main {
const _ code ← 200
switch code {
case 200 {
print "ok"
}
default {
print "other"
}
}
}Expected output:
ok