Hi,
Official documentation only says " To access the index of iteration, specify a second condition as well as a second capture value.".
My program example:
const std = @import("std");
pub fn main() void {
var arr = [_]u8{ 0, 0, 0, 0, 0 };
for (&arr, 2..) |*val, i| {
val.* = 1; // this is ok
val[i] = 1; // panic: index out of bounds
}
}
Expected behavior: loop starts with i == 2, val == arr[2] and ends with i == arr.len - 1.
Actual behavior: loop starts with i == 2, val == arr[0] and ends (if comment out line with val[i]) with i == 2 + arr.len - 1.
Spent a couple hours in a more complex context to figure it out. 😐
My question: what the second condition actually is and how it is related to the loop? Is it documented or explained anywhere?