Complete the code to print numbers from 1 to 5 using a loop.
for i in 1..=[1] { println!("{}", i); }
The range 1..=5 includes numbers from 1 to 5, so the loop prints 1 to 5.
Complete the code to skip printing the number 3 inside the loop.
for i in 1..=5 { if i == [1] { continue; } println!("{}", i); }
The continue statement skips the current loop iteration when i equals 3, so 3 is not printed.
Fix the error in the loop to stop printing numbers when i equals 4.
for i in 1..=5 { if i == [1] { break; } println!("{}", i); }
The break statement stops the loop when i equals 4, so numbers 1 to 3 are printed.
Fill both blanks to create a loop that prints only even numbers from 1 to 10.
for i in 1..=[1] { if i % 2 [2] 0 { println!("{}", i); } }
The loop runs from 1 to 10. The condition i % 2 == 0 checks if i is even, so only even numbers are printed.
Fill all three blanks to create a loop that collects numbers greater than 3 into a vector.
let mut result = Vec::new(); for num in 1..=[1] { if num [2] [3] { result.push(num); } } println!("{:?}", result);
The loop runs from 1 to 5. The condition num > 3 selects numbers greater than 3, which are pushed into the vector. The output will be [4, 5].