Created
November 16, 2018 23:35
-
-
Save oconnor0/4e23d7db2482bd8c82df23584ee44173 to your computer and use it in GitHub Desktop.
Another iterable range implementation in zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const warn = @import("std").debug.warn; | |
pub fn inclusive_range(comptime Int: type, comptime lower: Int, comptime upper: Int) [upper-lower+1]Int { | |
var values: [upper-lower+1]Int = undefined; | |
var i: Int = lower; | |
while (i <= upper) : (i += 1) { | |
values[i - lower] = i; | |
} | |
return values; | |
} | |
pub fn main() void { | |
for (inclusive_range(u64, 2, 72)) |i| { | |
warn("i {}\n", i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fancy