June 2021
Beginner
344 pages
8h 9m
English
The treehouse is an exclusive club. Only individuals on the approved list of friends are allowed inside. You could accomplish this with if statements. If you only want to admit your friend “Bert,” you could use the following code:
| | if your_name == "bert" { |
| | println!("Welcome."); |
| | } else { |
| | println!("Sorry, you are not on the list.") |
| | } |
The if/else control flow system works much like it does in other programming languages: if the condition is true, then it executes the code in the first block. Otherwise, it runs the code in the else block.
When you do your comparison, make sure that you compare your string with “bert” in lowercase. You need to use lowercase because the input function converts the user’s ...
Read now
Unlock full access