การเรนเดอร์th-TH

เลือก

Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.

Starts a value-based branch statement.

Aliases: switch, choose

Syntax: เลือก <expression> <block>

Category#

control-flow

Examples#

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

Starts a value-based branch statement.

# =============================================================================
# เลือก — Starts a value-based branch statement.
# =============================================================================
#
# What this teaches:
#   • Value-based branching — `เลือก <expr> { กรณี <value> { ... } }` dispatches on a value (switch/choose pattern).
#   • Multiple types — `เลือก` works with ข้อความ, จํานวน, and other comparable types.
#   • Multi-statement cases — each `กรณี` block can have multiple statements.
#
# Common mistakes:
#   • Non-exhaustive `เลือก` without `อื่น` — unmatched values silently produce no output; use `อื่น` for a default branch or cover all possible values.
#
# See also: กรณี, อื่น
# =============================================================================

# เลือก — switch on a value
#
# เลือก <expr> {
#     กรณี <value> { <body> }
#     อื่น { <body> }
# }
#
# GRAMMAR:
#   eligeStmt :← 'เลือก' expr '{' casuClause* '}'
#
# EXPECTED OUTPUT:
#   elige.expected

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

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

    # Multiple statements per case
    const 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