Hacker News new | ask | show | jobs
by biryani_chicken 1557 days ago
Some of the comments in the page mention Zig. While Zig has iterators for slices, the simple "for" loop (that actually uses the while keyword) makes you define the variable outside the loop:

    var i: usize = 0;
    while (i < 10): (i += 1) {
        //use i
    }
I hope they fix this before 1.0.
2 comments

I don't use Zig but follow its development a bit. Zig has or may add foreach-like loops over one or more collections: https://github.com/ziglang/zig/issues/7257#issuecomment-1030...
I watched Jonathan Blow's introduction to macros in the Jai language[1] that he develops. Basically he made the for loop to be a macro (what he called a "hygienic macro") and it can be overloaded for various types of iterators. (watch past minute 6:30)

[1] https://www.youtube.com/watch?v=QX46eLqq1ps