From a3450d687628661aa0316cfc995934f6ce0c4e90 Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 19:56:53 +0330 Subject: defer: any single statement (if/else, loops, switch, unchecked, unbounded), not just an expression or a block --- docs/LEARN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/LEARN.md') 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): -- cgit v1.2.3