loop structure.

This commit is contained in:
licsber 2024-08-21 17:08:27 +08:00
parent 31a6753312
commit 35796d912b

View File

@ -7,6 +7,7 @@ fn main() {
println!("Secret number is {:?}", secret_number); println!("Secret number is {:?}", secret_number);
loop {
println!("Guessing a number:"); println!("Guessing a number:");
let mut guess_number = String::new(); let mut guess_number = String::new();
@ -22,6 +23,10 @@ fn main() {
match guess_number.cmp(&secret_number) { match guess_number.cmp(&secret_number) {
Ordering::Less => println!("Too small."), Ordering::Less => println!("Too small."),
Ordering::Greater => println!("Too big."), Ordering::Greater => println!("Too big."),
Ordering::Equal => println!("You win!") Ordering::Equal => {
println!("You win!");
break;
}
}
} }
} }