Complete the code to break the loop when the counter reaches 3.
let mut count = 0; loop { count += 1; if count == [1] { break; } } println!("Count stopped at {}", count);
The loop breaks when count equals 3, stopping the loop at the right time.
Complete the code to break the loop when the input number is zero.
let mut input = 5; loop { if input == [1] { break; } input -= 1; } println!("Loop ended because input is zero.");
The loop breaks when input reaches zero, stopping the countdown.
Fix the error in the loop to break when the variable reaches 4.
let mut num = 0; loop { num += 1; if num == [1] { break; } } println!("Stopped at {}", num);
The loop should break when num equals 4, so the correct value is 4.
Fill both blanks to create a loop that breaks when the counter is less than 2.
let mut counter = 5; loop { counter -= 1; if counter [1] [2] { break; } } println!("Counter stopped at {}", counter);
The loop breaks when counter < 2, so the operator is < and the number is 2.
Fill all three blanks to break the loop when the value is greater than 7 and print the value.
let mut value = 0; loop { value += 2; if value [1] [2] { break; } } println!("Value is [3]", value);
The loop breaks when value > 7. The print uses {} to show the value.
