渲染zh-Hant

執行

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.

Starts a scoped do-while style loop.

Aliases: do

Syntax: 執行 <block> [捕捉 <name> <block>] [當 <condition>]

Category#

control-flow

Examples#

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

Starts a scoped do-while style loop.

# =============================================================================
# 執行 — Starts a scoped do-while style loop
# =============================================================================
#
# What this teaches:
#   • Starts a scoped do-while style loop.
#   • Related keywords: 當, 捕捉, 閉包, 繼續
#
# Common mistakes:
#   • Using `捕捉` on a non-`執行` block — `捕捉` only attaches to `執行` statements, not arbitrary blocks.
#
# See also: 當, 捕捉, 閉包, 繼續
# =============================================================================

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

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

    # 拋出 on second attempt; 捕捉 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)
    }
}