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.

switch

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Starts a value-based branch statement.

Aliases: switch, choose

Syntax: switch <expression> <block>

Category#

branch

Examples#

radix/corpus/reference/keyword/elige/elige.fab (canonical · keyword)#

Starts a value-based branch statement.

# =============================================================================
# switch — Starts a value-based branch statement.
# =============================================================================
#
# What this teaches:
#   • Value-based branching — `switch <expr> { case <value> { ... } }` dispatches on a value (switch/choose pattern).
#   • Multiple types — `switch` works with string, int, and other comparable types.
#   • Multi-statement cases — each `case` block can have multiple statements.
#
# Common mistakes:
#   • Non-exhaustive `switch` without `default` — unmatched values silently produce no output; use `default` for a default branch or cover all possible values.
#
# See also: case, default
# =============================================================================

# switch — switch on a value
#
# switch <expr> {
#     case <value> { <body> }
#     default { <body> }
# }
#
# GRAMMAR:
#   eligeStmt :← 'switch' expr '{' casuClause* '}'
#
# EXPECTED OUTPUT:
#   elige.expected

main {
    # Text matching
    let string condicio ← "agens"
    switch condicio {
        case "pendens" {
            print "exspectat..."
        }
        case "agens" {
            print "currit"
        }
        case "perfectum" {
            print "perfectum"
        }
    }

    # Numerus matching
    let int codex ← 200
    switch codex {
        case 200 {
            print "Recte"
        }
        case 404 {
            print "non inventum"
        }
        case 500 {
            print "error ministri"
        }
    }

    # Multiple statements per case
    let string modus ← "opera"
    switch modus {
        case "labor" {
            print "modus laboris"
            print "verba multa"
        }
        case "opera" {
            print "modus operis"
            print "opera parata"
        }
    }
}

Expected output:

currit
Recte
modus operis
opera parata