Complete the code to print each number from 1 to 3.
for [1] in 1..4 { println!("{}", [1]); }
The variable num is used as the loop variable to iterate over the range 1..4.
Complete the code to sum numbers from 1 to 5 using a for loop.
let mut sum = 0; for [1] in 1..6 { sum += [1]; } println!("Sum: {}", sum);
sum as mutable.The variable i is used as the loop variable to add each number to sum.
Fix the error in the for loop to print each element in the vector.
let numbers = vec![10, 20, 30]; for [1] in &numbers { println!("{}", [1]); }
The loop variable num iterates over references to elements in the vector numbers.
Fill both blanks to create a for loop that prints even numbers from 2 to 10.
for [1] in (2..11).step_by([2]) { println!("{}", [1]); }
The variable num iterates over the range stepping by 2 to print even numbers.
Fill all three blanks to create a for loop that prints the squares of numbers from 1 to 5.
for [1] in 1..6 { let square = [2] [3] [2]; println!("{}", square); }
The loop variable x is used to calculate the square using multiplication x * x.
