渲染zh-Hant

否則若

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

Adds an else-if branch after a previous 若 branch.

Aliases: else if

Syntax: 否則若 <condition> <block>

Category#

control-flow

Examples#

radix/corpus/si/sin.fab (canonical · keyword)#

Adds an else-if branch after a previous 若 branch.

# =============================================================================
# 否則若 — Adds an else-if branch after a previous 若 branch.
# =============================================================================
#
# What this teaches:
#   • Else-if chains — `否則若 <condition> { body }` adds intermediate conditional
#     branches between `若` and `否則`
#   • First match wins: evaluation stops at the first `若` or `否則若` whose
#     condition is `真`
#
# Common mistakes:
#   • TODO: forgetting that `否則若` blocks are skipped once a preceding branch
#     matches
#
# See also: 若, 否則
# =============================================================================

# si-sin-secus (poetic if-else-if chain)
#
# 若 <cond> { }
# 否則若 <cond> { }
# 否則 { }
#
# GRAMMAR:
#   ifStmt :← '若' expr block ('否則若' expr block)* ('否則' block)?
#
# EXPECTED OUTPUT:
#   Afternoon (hour=14 matches first 否則若 branch).

main {
    const int hour ← 14
    if hour ≺ 6 {
        print "Late night"
    }
    elif hour ≺ 12 {
        print "Morning"
    }
    elif hour ≺ 18 {
        # 14 ≥ 12 and 14 < 18
        print "Afternoon"
    }
    elif hour ≺ 22 {
        print "Evening"
    }
    else {
        print "Night"
    }
}

Expected output:

Afternoon

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

Adds an else-if branch after a previous 若 branch.

# =============================================================================
# 否則若 — Adds an else-if branch after a previous 若 branch.
# =============================================================================
#
# What this teaches:
#   • Standalone else-if — `否則若` provides an intermediate conditional branch
#     evaluated only when the preceding `若` condition was `假`
#   • Chains: `若 { } 否則若 { } 否則 { }` for multi-way branching
#
# Common mistakes:
#   • Writing `否則 若` instead of the canonical `否則若` for else-if branches.
#
# See also: 若, 否則
# =============================================================================

# 否則若 — else-if branch
#
# GRAMMAR:
#   elseIfClause :← '否則若' expr block
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#
# BACKEND:
#   Cross-ref: 若/sin.fab.
#

main {
    const int score ← 85
    if score ≥ 90 {
        print "excellent"
    }
    elif score ≥ 80 {
        print "good"
    }
    else {
        print "needs work"
    }
}

Expected output:

good