do
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Starts a scoped do-while style loop.
Aliases: do
Syntax: do <block> [catch <name> <block>] [while <condition>]
Category#
control-flow
Related#
Examples#
radix/corpus/fac/fac-cape.fab (canonical · keyword)#
Starts a scoped do-while style loop.
# =============================================================================
# do — Starts a scoped do-while style loop
# =============================================================================
#
# What this teaches:
# • Starts a scoped do-while style loop.
# • Related keywords: while, catch, lambda, continue
#
# Common mistakes:
# • Using `catch` on a non-`do` block — `catch` only attaches to `do` statements, not arbitrary blocks.
#
# See also: while, catch, lambda, continue
# =============================================================================
# do — try block with catch error handler
#
# do { <body> }
# catch err { <handler> }
#
# GRAMMAR:
# facStmt :← 'do' block 'catch' ident block
#
# EXPECTED OUTPUT:
# none — success path then simulated failure on attempt 2
#
# BACKEND:
# Rust/Go: do/cape not yet emitted — compile-only smoke.
main {
do {
print "Block executed successfully"
}
catch err {
print "Caught error: §"(err.nuntius)
}
# throw on second attempt; catch 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)
}
}