1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-16 06:10:26 +02:00
Files
comprehensive-rust/src/control-flow-basics/loops/for.md
Manichand Kondapaka 345cf646e4 Added loops section (#1789)
This is a contribution of a loops section for Comprehensive Rust.
2024-02-07 19:33:49 +00:00

396 B

for

The for loop iterates over ranges of values:

fn main() {
    for x in 1..5 {
        println!("x: {x}");
    }
}
  • We will discuss iteration later; for now, just stick to range expressions.
  • Note that the for loop only iterates to 4. Show the 1..=5 syntax for an inclusive range.