若
Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant 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