Personally I would really like a reverse for, it’s kinda awkward to do the same thing with a while.
// 4 3 2 1 0
reverse for (0..5) |i| {
std.debug.print("{} ", .{i});
}
Personally I would really like a reverse for, it’s kinda awkward to do the same thing with a while.
// 4 3 2 1 0
reverse for (0..5) |i| {
std.debug.print("{} ", .{i});
}
I doubt 0..array.len syntax will be changed, as most used and most convenient.
However, if we really want to cover those rare cases, clearly making them different from normal array-safe-ranges to avoid mistakes, and without overflow issue, maybe add something to be used inside for syntax:
@inclusiveRange(0, 5) // 0,1,2,3,4,5
@exclusiveRange(0, 5) // 1,2,3,4
or: ..Range(0..5) / …Range(arr) syntax too
Maybe one could create functions, except not sure how to handle (+1 ) overflow properly then, and use with for(exclusiveRange(0, 5)). If done with buildins, I assume overflow is just optimized out inside for code generated, so >= vs. > or so in asm/IR/something, no op to prevent it.