Exerpad
🔥 0
0 XP
Exercise 4 · Chapter: While LoopsRequired+50 XP

Sum Numbers

Use a while loop to add up all the numbers from 1 to 10, then print the result.

Expected output:

Sum: 55

Hints:

  • You'll need two mutable variables: one for the counter and one for the total
  • Start with let mut sum = 0; and let mut i = 1;
  • Add i to sum each time through the loop
  • Print the sum after the loop using println!("Sum: {}", sum);
rust
fn main() {
}
Output
Run your code to see the output here.