Created
August 12, 2018 10:06
-
-
Save rust-play/a2271c70a6612c6275bc04d5e4737374 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
fn main() { | |
loop { | |
println!("Please input your guess."); | |
let mut input = String::new(); | |
io::stdin().read_line(&mut input).expect("Failed to read line"); | |
let input = input.trim(); | |
let guess: u32 = match input.parse() { | |
Ok(num) => num, | |
Err(_) => { | |
if input == "exit" { | |
println!("bye"); | |
break; | |
} else { | |
println!("Enter a number, please."); | |
continue; | |
} | |
} | |
}; | |
println!("guess = {}", guess); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment