aboutsummaryrefslogtreecommitdiff
path: root/docs/LEARN.md
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 19:56:53 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 19:56:53 +0330
commit28c43908844cbf27ca74edf3990084abd73e2c96 (patch)
treea023f2a33928fefd83745b2995ee8fe70c5424f4 /docs/LEARN.md
parentzy: nonzero exit on compile errors (diff)
defer: any single statement (if/else, loops, switch, unchecked, unbounded), not just an expression or a blockwork/defer
Diffstat (limited to 'docs/LEARN.md')
-rw-r--r--docs/LEARN.md2
1 files changed, 1 insertions, 1 deletions
diff --git a/docs/LEARN.md b/docs/LEARN.md
index e9cdbcf..fd399e3 100644
--- a/docs/LEARN.md
+++ b/docs/LEARN.md
@@ -176,7 +176,7 @@ output:
### defer
-`defer expr;` or `defer { statements }` runs code when the enclosing block ends: after the last statement, and also on `return`, `break` and `continue` out of it. defers in a block run last registered first. the deferred code is compiled at each exit, so it sees the variables as they are when it runs, and `return e;` computes `e` before any defer runs. `defer rt.free(p);` hands the owner `p` over at that point: `p` stays usable until the block ends and is not freed twice. `return`, `break` and `continue` are not allowed inside a deferred statement.
+`defer expr;`, `defer { statements }` or any other single statement (`defer if (c) a; else b;`, a loop, a `switch`) runs code when the enclosing block ends: after the last statement, and also on `return`, `break` and `continue` out of it. defers in a block run last registered first. the deferred code is compiled at each exit, so it sees the variables as they are when it runs, and `return e;` computes `e` before any defer runs. `defer rt.free(p);` hands the owner `p` over at that point: `p` stays usable until the block ends and is not freed twice. `return`, `break` and `continue` are not allowed inside a deferred statement.
[example source](../examples/learn/34-defer.zc):