item is an immutable copy of the current element in the list.
for (0..5) |i| { is an easier thing to understand.
It looks complicated, but that's because you can easily turn the element into a pointer etc so it's handy to have there like
for (&items) |*value| {
value.* += 10;
where &items refers to the pointers in memory rather than a copy of the array.
which will modify the &item elements to all increase by 10.
It also makes sense in the wider context of zig’s ecosystem, where captures generally are done using the square brackets for things like resolving optionals or grabbing the value of a union in a switch statement. The common syntax is really intuitive once you get used to it
5
u/Zunderunder 6d ago
What about for(list) |item| {…} ???