Defer block cleanup
defer statement schedules work when the enclosing block exits. Defers are block-scoped and run in reverse registration order on fall-through, return, propagation, break, or continue.
They read current values at exit time. Runtime errors abort without running them, and a defer body cannot redirect control with return, propagation, or await.
fn main() {
defer println("first")
defer println("second")
println("work")
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: work second first
Ctrl/⌘+Enter runs the current lesson.