The while loop never stops in the following code. I am trying to implement the guessing game in Chapter 2 of the official documentation of Rust. I am new to Rust. Help/explanation will be appreciated.
use std::io;
use rand::Rng;
fn main() {
println!("Guessing Game");
println!("Enter guess: ");
let mut guess = String::new();
io::stdin().read_line(&mut guess).expect("Failed to read line!");
println!("You guessed: {}", guess);
let secret_num = rand::thread_rng().gen_range(1..5);
while guess != secret_num.to_string() {
println!("Wrong guess! The correct guess is {}", secret_num);
println!("\nEnter guess: ");
guess = String::new();
io::stdin().read_line(&mut guess).expect("Failed to read line!");
}
println!("You guessed the right number: {}", secret_num);
}