elif
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Adds an else-if branch after a previous if branch.
Aliases: else if
Syntax: elif <condition> <block>
Category#
control-flow
Related#
Examples#
radix/corpus/si/sin.fab (canonical · keyword)#
Adds an else-if branch after a previous if branch.
# =============================================================================
# elif — Adds an else-if branch after a previous if branch.
# =============================================================================
#
# What this teaches:
# • Else-if chains — `elif <condition> { body }` adds intermediate conditional
# branches between `if` and `else`
# • First match wins: evaluation stops at the first `if` or `elif` whose
# condition is `true`
#
# Common mistakes:
# • TODO: forgetting that `elif` blocks are skipped once a preceding branch
# matches
#
# See also: if, else
# =============================================================================
# si-sin-secus (poetic if-else-if chain)
#
# if <cond> { }
# elif <cond> { }
# else { }
#
# GRAMMAR:
# ifStmt :← 'if' expr block ('elif' expr block)* ('else' block)?
#
# EXPECTED OUTPUT:
# Afternoon (hour=14 matches first elif 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 if branch.
# =============================================================================
# elif — Adds an else-if branch after a previous if branch.
# =============================================================================
#
# What this teaches:
# • Standalone else-if — `elif` provides an intermediate conditional branch
# evaluated only when the preceding `if` condition was `false`
# • Chains: `if { } elif { } else { }` for multi-way branching
#
# Common mistakes:
# • Writing `else if` instead of the canonical `elif` for else-if branches.
#
# See also: if, else
# =============================================================================
# elif — else-if branch
#
# GRAMMAR:
# elseIfClause :← 'elif' expr block
#
# EXPECTED OUTPUT:
# Scalar stdout smoke (see body).
#
# BACKEND:
# Cross-ref: if/sin.fab.
#
main {
const int score ← 85
if score ≥ 90 {
print "excellent"
}
elif score ≥ 80 {
print "good"
}
else {
print "needs work"
}
}Expected output:
good