Rust Fundamentals · 20 XP Pro
Capstone: the clapping game
Time to combine for, ranges, if / else if / else and println!. The
remainder operator % is the key: n % 4 == 0 means "n is a multiple of 4".
Order matters in an else if chain: the first branch that matches wins, so test the
most specific case (a number that fits two rules) before the general ones.
for n in 1..=3 {
if n % 2 == 0 {
println!("even");
} else {
println!("{n}");
}
}
Your task
Write a main that counts from 1 to 20 inclusive, printing one line per number:
- multiples of 4 and 6 at once:
Clap-Stomp - multiples of 4:
Clap - multiples of 6:
Stomp - the number 13:
Unlucky - everything else: the number itself
The output starts 1, 2, 3, Clap, 5, Stomp and ends with 19, Clap.