Skip to content

Instantly share code, notes, and snippets.

@oconnor0
Created November 16, 2018 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oconnor0/4e23d7db2482bd8c82df23584ee44173 to your computer and use it in GitHub Desktop.
Save oconnor0/4e23d7db2482bd8c82df23584ee44173 to your computer and use it in GitHub Desktop.
Another iterable range implementation in zig
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);
}
}
@suirad
Copy link

suirad commented Nov 16, 2018

fancy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment