Iterating and Mutating Slices
Read and write through a slice.
Walking a Slice
Once you hold a slice, you usually want to visit every element. Zig's for loop iterates a slice cleanly from start to end. 🔁
The for Over Items
Put the slice in parentheses and name each element with a capture in pipes. The loop hands you one value per pass.
for (items) |value| {
// use value
}All lessons in this course
- Fixed-Size Arrays
- Slices: A Pointer Plus a Length
- Slicing with array[start..end]
- Iterating and Mutating Slices