Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

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#

branch

Examples#

radix/corpus/reference/keyword/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 {
    let _ code ← 200
    switch code {
        case 200 {
            print "ok"
        }
        default {
            print "other"
        }
    }
}

Expected output:

ok