Loop as expression
In Rust, loop can return a value:
let x = loop {
break 10;
};
The break 10 sets the loop's result to 10. This replaces the need for a separate result variable in many counting patterns.
Iterators
Iterators transform data lazily:
let nums = vec![1, 2, 3];
let doubled: Vec<i32> = nums.iter().map(|n| n * 2).collect();
map transforms each item; collect gathers results. Iterators are lazy, nothing runs until you call collect or another consuming method.