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