blocks
test.zig
Shell
docgen_tmp/test.zig:6:5: error: use of undeclared identifier 'x'
x += 1;
^
Blocks are expressions. When labeled, break
can be used to return a value from the block:
Shell
$ zig test test_labeled_break.zig
All 1 tests passed.
Here, blk
can be any name.
See also:
test.zig
Shell
$ zig test test.zig
docgen_tmp/test.zig:6:13: error: local shadows declaration of 'pi'
var pi: i32 = 1234;
docgen_tmp/test.zig:1:1: note: declared here
const pi = 3.14;
^
Because of this, when you read Zig code you can always rely on an identifier to consistently mean the same thing within the scope it is defined. Note that you can, however, use the same name if the scopes are separate:
Shell
$ zig test test_scopes.zig
1/1 test "separate scopes"... OK