Back to course

Inline Loops and Switches

Full Course: Zig Programming From Zero to Hero

Inline Loops

inline loops are unrolled at compile time. This is useful when you need to iterate over a tuple or a set of types.

zig const types = [_]type{ i32, f32, bool };

inline for (types) |T| { const x: T = undefined; std.debug.print("Type: {s}\n", .{@typeName(T)}); }

Similarly, inline switch can be used to generate code paths for different types or values at compile time.