Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

if

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Starts a conditional branch that runs when its condition is true.

Aliases: if

Syntax: if <condition> <block>

Category#

branch

Examples#

radix/corpus/reference/keyword/si/nidificatus.fab (canonical · keyword)#

Starts a conditional branch that runs when its condition is true.

# =============================================================================
# if — Starts a conditional branch that runs when its condition is true.
# =============================================================================
#
# What this teaches:
#   • Nested conditionals — `if` blocks can contain further `if`/`else`
#     branches for multi-level decision trees
#   • Demonstrates a login + permission gate: outer `if` checks authentication,
#     inner `if` checks authorization
#
# Common mistakes:
#   • TODO: deeply nesting conditionals instead of using `elif` chains or
#     guard returns
#
# See also: elif, else, then
# =============================================================================

# Nested if (if) conditionals
#
# if <cond> { <body> }                    -- inner branch inside outer arm
# else { <body> }
#
# GRAMMAR:
#   ifStmt :← 'if' expr block ('else' block)?
#
# EXPECTED OUTPUT:
#   Access granted when intravit and licet are both true.

main {
    # logged in
    let bool intravit ← true
    # has permission
    let 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/reference/keyword/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" {
    let int x ← 10
    mut bool maior ← false
    if x ≻ 5 {
        maior ← true
    }
    assert maior
}

test "si skips its body on a falsum condition" {
    let int x ← 10
    mut bool maior ← false
    if x ≻ 20 {
        maior ← true
    }
    assert not maior
}

test "si block body runs every statement" {
    let int aetas ← 25
    mut int gradus ← 0
    if aetas ≥ 18 {
        gradus ← gradus + 1
        gradus ← gradus + 1
    }
    assert gradus ≡ 2
}
# =============================================================================
# if — Starts a conditional branch that runs when its condition is true.
# =============================================================================
#
# What this teaches:
#   • Basic conditional execution — `if <condition> { body }` runs the body
#     only when the condition evaluates to `true`
#   • Multiple independent `if` blocks can be chained; each evaluates its own
#     condition independently
#
# Common mistakes:
#   • Using a non-`bool` expression as the `if` condition (SEM011), or using `∴` instead of `then` for a single-statement body.
#
# See also: elif, else, then
# =============================================================================

# Basic if (if) conditionals
#
# if <condition> { <body> }   -- truthy branch
#
# GRAMMAR:
#   ifStmt :← 'if' expr block
#
# EXPECTED OUTPUT:
#   x maior quam 5, Adult, Can vote (si.expected).

main {
    # Simple truthy branch — only the first condition matches
    let 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
    let int aetas ← 25
    if aetas ≥ 18 {
        print "Adult"
        print "Can vote"
    }
}

Expected output:

x maior quam 5
Adult
Can vote

radix/corpus/reference/reject/si/else-if-reject.fab (supporting · reject)#

The else if spelling is refused; use elif to continue a conditional ladder.

# =============================================================================
# if — the `else if` spelling is refused
#
# Continue a conditional ladder with `elif`; `else if` is not a second spelling.
# =============================================================================

main {
    let int n ← 5
    if n ≺ 0 { print "a" } else if n ≺ 10 { print "b" } else { print "c" }
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/si/shadow-reject.fab (supporting · reject)#

Shadowing a local name is refused in a nested block.

# =============================================================================
# if — local variable shadowing is refused
#
# Give each local binding a distinct name, including inside conditional blocks.
# =============================================================================

main {
    let int x ← 1
    if true {
        let int x ← 2
        print x
    }
    print x
}

Expected: compilation rejects this example.