In this video, use the loop functionality in Rust to allow 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 user wins.…Now let's go ahead and do that.…
- Installing Rust
- Data types
- Adjusting memory allocation
- Setting up race conditions
- Working with functions
- Exploring references and borrowing
- Using structs
- Method syntax
- Demonstrating recoverable errors with Result
- Working with enums
- Getting user input
Skill Level Beginner
1. Hello, Rust!
2. Basic Programming Concepts
3. Ownership in Rust
4. Data Handling and Pattern Matching in Rust
5. Error Handling
6. Sample Rust Project: The Guessing Game
Next steps1m 14s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.