for

    Shell

    1. 1/3 test "for basics"... OK
    2. 2/3 test "for reference"... OK
    3. 3/3 test "for else"... OK

    When a loop is labeled, it can be referenced from a break or continue from within a nested loop:

    Shell

    1. $ zig test test_nested_break.zig
    2. 1/2 test "nested break"... OK
    3. All 2 tests passed.

    inline for

    For loops can be inlined. This causes the loop to be unrolled, which allows the code to do some things which only work at compile time, such as use types as first class values. The capture value and iterator value of inlined for loops are compile-time known.

    Shell

    1. $ zig test test_inline_loop.zig
    2. 1/1 test "inline for loop"... OK

    It is recommended to use loops only for one of these reasons:

    • You need the loop to execute at for the semantics to work.
    • You have a benchmark to prove that forcibly unrolling the loop in this way is measurably faster.