Skip to main content

2 docs tagged with "for"

View all tags

Iterating over Collections

In the previous article, we introduced the for loop and used it to iterate over a range of numbers. The true power of for loops, however, comes from their ability to iterate over collections like arrays, vectors, and more. This is the most common and idiomatic way to work with collections in Rust.

Loops: `for` loops and the `..` range operator

We've explored loop for infinite loops and while for conditional loops. Now, we'll look at the most common and often most powerful loop in Rust: the for loop. for loops are excellent for executing a block of code a specific number of times and for iterating over collections.