How to Use Ranges in Rust (1..10 vs 1..=10)

Use 1..10 for exclusive ranges and 1..=10 for inclusive ranges in Rust loops.

Use 1..10 for an exclusive range that stops before the end value, and 1..=10 for an inclusive range that includes the end value.

let exclusive = 1..10;  // 1, 2, ..., 9
let inclusive = 1..=10; // 1, 2, ..., 10

for i in 1..10 {
    println!("exclusive: {i}");
}

for i in 1..=10 {
    println!("inclusive: {i}");
}