mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-04 16:47:25 +02:00
As mentioned in #2478, this cleans up the code blocks when all that is needed is a trivial debug print statement. Only making changes to Day 1 morning session so that I can get feedback before proceeding with the rest of the course. --------- Co-authored-by: Eric Githinji <egithinji@google.com>
586 B
586 B
for
The for
loop iterates over
ranges of values or the items in a collection:
fn main() {
for x in 1..5 {
dbg!(x);
}
for elem in [2, 4, 8, 16, 32] {
dbg!(elem);
}
}
- Under the hood
for
loops use a concept called "iterators" to handle iterating over different kinds of ranges/collections. Iterators will be discussed in more detail later. - Note that the first
for
loop only iterates to4
. Show the1..=5
syntax for an inclusive range.