diff options
| author | 2026-10-14 19:56:53 +0330 | |
|---|---|---|
| committer | 2026-10-14 21:24:34 +0330 | |
| commit | a3450d687628661aa0316cfc995934f6ce0c4e90 (patch) | |
| tree | 75ed354e2c274317df25e3dcdd9ab5ea72dff2f2 /docs/LEARN.md | |
| parent | todo: run.py's sieve checksum fails on main (diff) | |
defer: any single statement (if/else, loops, switch, unchecked, unbounded), not just an expression or a block
Diffstat (limited to 'docs/LEARN.md')
| -rw-r--r-- | docs/LEARN.md | 2 |
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): |
