渲染zh-Hant

fac

Translation status: 繁體中文 reader-locale proof. Code fences render through the zh-Hant pipeline; prose is canonical Latin.

Starts a scoped do-while style loop.

Aliases: do

Syntax: fac <block> [cape <name> <block>] [dum <condition>]

Category#

control-flow

Examples#

radix/corpus/fac/fac-cape.fab (canonical · keyword)#

Starts a scoped do-while style loop.

# =============================================================================
# fac — Starts a scoped do-while style loop
# =============================================================================
#
# What this teaches:
#   • Starts a scoped do-while style loop.
#   • Related keywords: dum, cape, clausura, perge
#
# Common mistakes:
#   • Using `cape` on a non-`fac` block — `cape` only attaches to `fac` statements, not arbitrary blocks.
#
# See also: dum, cape, clausura, perge
# =============================================================================

# fac — try block with cape error handler
#
# fac { <body> }
# cape err { <handler> }
#
# GRAMMAR:
#   facStmt :← 'fac' block 'cape' ident block
#
# EXPECTED OUTPUT:
#   none — success path then simulated failure on attempt 2
#
# BACKEND:
#   Rust/Go: fac/cape not yet emitted — compile-only smoke.

main {
    do {
        print "Block executed successfully"
    }
    catch err {
        print "Caught error: §"(err.nuntius)
    }

    # iace on second attempt; cape recovers and prints err.nuntius
    var int attempts  0
    do {
        attempts  attempts + 1
        print "Attempt §"(attempts)
        if attempts  2 {
            throw "Simulated failure"
        }
    }
    catch err {
        print "Failed on attempt §: §"(attempts, err.nuntius)
    }
}