रेंडरिंगhi

यदि

Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi 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

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