blocks

    test.zig

    Shell

    1. docgen_tmp/test.zig:6:5: error: use of undeclared identifier 'x'
    2. x += 1;
    3. ^

    Blocks are expressions. When labeled, break can be used to return a value from the block:

    Shell

    1. $ zig test test_labeled_break.zig
    2. All 1 tests passed.

    Here, blk can be any name.

    See also:

    test.zig

    Shell

    1. $ zig test test.zig
    2. docgen_tmp/test.zig:6:13: error: local shadows declaration of 'pi'
    3. var pi: i32 = 1234;
    4. docgen_tmp/test.zig:1:1: note: declared here
    5. const pi = 3.14;
    6. ^

    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

    1. $ zig test test_scopes.zig
    2. 1/1 test "separate scopes"... OK