Exercise 2 · Chapter: For LoopsRequired+50 XP
Count by Twos
Use a for loop with .step_by() to print the even numbers from 2 to 10, one per line.
Expected output:
2 4 6 8 10
Hints:
- Use an inclusive range
2..=10 - Chain
.step_by(2)to skip every other number - Don't forget the parentheses around the range!
rust
fn main() {
}
Output
Run your code to see the output here.