Core Beginner
02 Control flow
Loops and conditionals: sum a range, then write the classic fizzbuzz for a single number.
Sum 1, 2, ..., n in sum_to.
Hints
for i in 1..=n { ... }iterates inclusively.
Reveal solution
fn sum_to(n: u32) -> u32 {
let mut total = 0;
for i in 1..=n {
total += i;
}
total
}