ถ้า
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.
Starts a conditional branch that runs when its condition is true.
Aliases: if
Syntax: ถ้า <condition> <block>
Category#
control-flow
Related#
Examples#
radix/corpus/si/nidificatus.fab (canonical · keyword)#
Starts a conditional branch that runs when its condition is true.
# =============================================================================
# ถ้า — Starts a conditional branch that runs when its condition is true.
# =============================================================================
#
# What this teaches:
# • Nested conditionals — `ถ้า` blocks can contain further `ถ้า`/`มิฉะนั้น`
# branches for multi-level decision trees
# • Demonstrates a login + permission gate: outer `ถ้า` checks authentication,
# inner `ถ้า` checks authorization
#
# Common mistakes:
# • TODO: deeply nesting conditionals instead of using `ถ้าไม่ก็` chains or
# guard returns
#
# See also: ถ้าไม่ก็, มิฉะนั้น, ดังนั้น
# =============================================================================
# Nested ถ้า (if) conditionals
#
# ถ้า <cond> { <body> } -- inner branch inside outer arm
# มิฉะนั้น { <body> }
#
# GRAMMAR:
# ifStmt :← 'ถ้า' expr block ('มิฉะนั้น' block)?
#
# EXPECTED OUTPUT:
# Access granted when intravit and licet are both จริง.
main {
# logged in
const bool intravit ← true
# has permission
const bool licet ← true
if intravit {
# Inner branch: permission check after login succeeds
if licet {
print "Access granted"
}
else {
print "Permission denied"
}
}
else {
# outer else: not logged in
print "Please log in"
}
}Expected output:
Access granted
radix/corpus/si/si.fab (canonical · keyword)#
Starts a conditional branch that runs when its condition is true.
test "si runs its body on a verum condition" {
const int x ← 10
var bool maior ← false
if x ≻ 5 {
maior ← true
}
assert maior
}
test "si skips its body on a falsum condition" {
const int x ← 10
var bool maior ← false
if x ≻ 20 {
maior ← true
}
assert not maior
}
test "si block body runs every statement" {
const int aetas ← 25
var int gradus ← 0
if aetas ≥ 18 {
gradus ← gradus + 1
gradus ← gradus + 1
}
assert gradus ≡ 2
}
# =============================================================================
# ถ้า — Starts a conditional branch that runs when its condition is true.
# =============================================================================
#
# What this teaches:
# • Basic conditional execution — `ถ้า <condition> { body }` runs the body
# only when the condition evaluates to `จริง`
# • Multiple independent `ถ้า` blocks can be chained; each evaluates its own
# condition independently
#
# Common mistakes:
# • Using a non-`ตรรกะ` expression as the `ถ้า` condition (SEM011), or using `∴` instead of `ดังนั้น` for a single-statement body.
#
# See also: ถ้าไม่ก็, มิฉะนั้น, ดังนั้น
# =============================================================================
# Basic ถ้า (if) conditionals
#
# ถ้า <condition> { <body> } -- truthy branch
#
# GRAMMAR:
# ifStmt :← 'ถ้า' expr block
#
# EXPECTED OUTPUT:
# x maior quam 5, Adult, Can vote (si.expected).
main {
# Simple truthy branch — only the first condition matches
const int x ← 10
if x ≻ 5 {
print "x maior quam 5"
}
if x ≻ 20 {
# skipped: 10 ≯ 20
print "x maior quam 20"
}
# Block body: multiple statements run together when condition holds
const int aetas ← 25
if aetas ≥ 18 {
print "Adult"
print "Can vote"
}
}Expected output:
x maior quam 5
Adult
Can vote