Kết xuấtvi

trường_hợp

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Introduces a branch inside an chọn or phân_tích statement.

Aliases: case

Syntax: trường_hợp <expression> <block>

Category#

control-flow

Examples#

radix/corpus/casu/casu.fab (canonical · keyword)#

Introduces a branch inside an chọn or phân_tích statement.

# =============================================================================
# trường_hợp — Introduces a branch inside an chọn or phân_tích statement.
# =============================================================================
#
# What this teaches:
#   • Pattern matching arms — `trường_hợp <expression> <block>` defines a branch in
#     an `chọn` match expression
#   • Default fallback — `mặc_định` provides the catch-all branch when no
#     `trường_hợp` pattern matches
#
# Common mistakes:
#   • non-exhaustive match without a `mặc_định` catchall — every `chọn` or `phân_tích` must cover all possibilities or add a `mặc_định` arm
#
# See also: chọn, phân_tích
# =============================================================================

# trường_hợp — branch arm in chọn or phân_tích
#
# GRAMMAR:
#   casuClause :← 'trường_hợp' expr block
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#
# BACKEND:
#   Cross-ref: chọn/elige.fab, phân_tích/discerne.fab.
#

main {
    const _ code ← 200
    switch code {
        case 200 {
            print "ok"
        }
        default {
            print "other"
        }
    }
}

Expected output:

ok