ถ้าไม่ก็
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH 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