Conceptual
Login

Iterating Over a Slice with a For Loop

A for loop walks every item in a collection in order, handing you one at a time, without you managing an index. Because the loop knows where the data ends, it cannot walk off the edge. This is the ordinary way to read or fill a buffer in Rust.

Questions this Concept answers

  • Why can a `for` loop over a slice not run past the end of the buffer?