การเรนเดอร์th-TH

ทำ

Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH 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)
    }
}