Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 12, 2018 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/a2271c70a6612c6275bc04d5e4737374 to your computer and use it in GitHub Desktop.
Save rust-play/a2271c70a6612c6275bc04d5e4737374 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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