3 ms·
Not a Zig programmer, but that looks horrible.
by tored 5y ago
Not a Zig programmer, but that looks horrible.
- AnIdiotOnTheNet 5y agoYeah, it's a hack. If you're doing it a lot you can abstract it into a function to clean it up: fn count(comptime n: usize) [n]u0 { return [1]u0{0} ** n; } for (count(10)) |_, i| { std.debug.print("{d}", .{i}); } or, if you don't need to capture the index: for (count(9)) |_| { //I can do it 9 times } Personally I've found I rarely need this kind of loop, so I just use the 'while' formulation because it is more obvious.
- dnautics 5y agoHah! i thought it was not a hack so much as a 'joke' that someone had discovered and posted to the discord, to much amusement. Are people actually using this? I will be amused when std.math.range shows up with this implementation.