What is the difference between iter map and for loop

The `for` loop executes code for each item immediately, while `.map()` transforms items into a new iterator for later consumption.

The for loop iterates over a collection by calling next() on an iterator, while .map() transforms each item in an iterator into a new value without executing the transformation until the iterator is consumed. Use for when you need to perform side effects like printing or modifying state, and use .map() when you want to create a new collection of transformed data.

let numbers = vec![1, 2, 3];

// for loop: executes immediately for side effects
for n in &numbers {
    println!("Got: {}", n);
}

// .map(): creates a new iterator of transformed values
let doubled: Vec<i32> = numbers.iter().map(|n| n * 2).collect();