否则如果
Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans 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
Related#
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