From the course: First Look: Rust

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Allowing multiple guesses

Allowing multiple guesses - Rust Tutorial

From the course: First Look: Rust

Start my 1-month free trial

Allowing multiple guesses

- [Instructor] Now all that's remaining is to allow the user to guess multiple times. The loop keyword gives us an infinite loop. Add that now to give users more chances at guessing the number. So we need to loop the code right from inputting the guess and all the way through the match operation. So at line 14, just say loop, followed by two curly braces, and then hit Enter here. All this code from line 17 up until line 32 has to go inside the loop, so just cut this code, and copy it here. Let's make sure that we've indented everything properly with four spaces. This whole thing, here. So now that we're indented okay, let's save this and see if the looping functionality works. So just say cargo run. And now the generated secret number is 68. Let's say I guess five. And that's too small. So let's say I guess something like 99, which is greater than 68, that's too big. And then once I say 68, it says you win. The problem here is that we haven't written code to quit the program when the…

Contents