1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-04 16:47:25 +02:00
Eric Githinji 0daab179e9
Use dbg! instead of println! in Day 1 mng session (#2652)
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>
2025-02-24 14:12:56 +00:00

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 to 4. Show the 1..=5 syntax for an inclusive range.