रेंडरिंगhi

अन्यथा

Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi pack; supporting prose may still be English.

Runs the fallback branch when preceding conditional branches do not match.

Aliases: else, otherwise

Syntax: अन्यथा <block>

Category#

control-flow

Examples#

radix/corpus/secus/secus.fab (canonical · keyword)#

Runs the fallback branch when preceding conditional branches do not match.

# =============================================================================
# अन्यथा — Runs the fallback branch when preceding conditional branches do not
# match.
# =============================================================================
#
# What this teaches:
#   • Conditional fallback — `अन्यथा` provides the else/otherwise branch that
#     runs when no preceding `यदि` or `अन्यथायदि` condition matched
#   • Always comes last in an if-else chain; takes a block body
#
# Common mistakes:
#   • Writing `अन्यथा यदि` instead of the canonical `अन्यथायदि` for else-if branches — `अन्यथा` must always be final.
#
# See also: यदि, अन्यथायदि
# =============================================================================

# अन्यथा — final else branch
#
# GRAMMAR:
#   elseClause :← 'अन्यथा' block
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#
# BACKEND:
#   Cross-ref: यदि/secus.fab.
#

main {
    const int hour ← 23
    if hour ≺ 12 {
        print "morning"
    }
    else {
        print "afternoon-or-later"
    }
}

Expected output:

afternoon-or-later

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

Runs the fallback branch when preceding conditional branches do not match.

# =============================================================================
# अन्यथा — Runs the fallback branch when preceding conditional branches do not
# match.
# =============================================================================
#
# What this teaches:
#   • If-else branches — `यदि { } अन्यथा { }` provides two-way branching; exactly
#     one arm executes
#   • `अन्यथायदि` chains additional conditions before the final `अन्यथा` fallback;
#     first match wins
#
# Common mistakes:
#   • TODO: placing `अन्यथा` before a `अन्यथायदि` branch — `अन्यथा` must always be the
#     final clause
#
# See also: यदि, अन्यथायदि
# =============================================================================

# si-secus (if-else) conditionals
#
# यदि <condition> { <body> }                                   -- two-way branch
# अन्यथा { <body> }
# यदि <cond1> { }                                              -- else-if chain
# अन्यथायदि <cond2> { }
# अन्यथा { }
#
# GRAMMAR:
#   ifStmt :← 'यदि' expr block ('अन्यथायदि' expr block)* ('अन्यथा' block)?
#
# EXPECTED OUTPUT:
#   Grade and weather messages for sample scores and temperatures.

main {
    # Two-way branch: exactly one arm runs
    const int puncta ← 85
    if puncta ≥ 90 {
        print "gradus: A"
    }
    else {
        # 85 < 90 → this arm
        print "gradus: B aut minor"
    }

    # Each branch may contain several statements
    const int calor ← 22
    if calor ≻ 30 {
        print "calidum"
        print "aquam bibe"
    }
    else {
        # 22 ≤ 30
        print "commodum"
        print "caelum mite"
    }

    # अन्यथायदि chains additional tests; first match wins (75 → C)
    const int gradus ← 75
    if gradus ≥ 90 {
        print "A - optimum"
    }
    elif gradus ≥ 80 {
        print "B - bonum"
    }
    elif gradus ≥ 70 {
        print "C - satis"
    }
    elif gradus ≥ 60 {
        print "D - transit"
    }
    else {
        print "F - deficit"
    }
}

Expected output:

gradus: B aut minor
commodum
caelum mite
C - satis