渲染zh-Hans

情况

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.

Introduces a branch inside an 选择 or 匹配 statement.

Aliases: case

Syntax: 情况 <expression> <block>

Category#

control-flow

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