blocks
test.zig
./docgen_tmp/test.zig:5: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:
$ zig test test.zig
All 1 tests passed.
Here, blk
can be any name.
See also:
test.zig
$ zig test test.zig
./docgen_tmp/test.zig:6:9: error: redefinition of 'pi'
^
const pi = 3.14;
^
Because of this, when you read Zig code you can rely on an identifier always meaning the same thing, within the scope it is defined. Note that you can, however use the same name if the scopes are separate:
$ zig test test.zig
Test [1/1] test "separate scopes"...
All 1 tests passed.