1. 7
    Rustlings if1: Using an if/else statement to implicitly (or explicitly) return a value
    1m 28s

Rustlings if1: Using an if/else statement to implicitly (or explicitly) return a value

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

README for this exercise.

Chris Biscardi: [0:01] After variables5, Rust takes us into the land of if statements. If we look at our program, we have a set of test. We'll mostly ignore tests for now, except to mention that they are written in the same file. If you have VS code plugged in, you can actually run the individual test on its own.

[0:24] Note that in our file, we have a function called bigger() that takes an a and a b, both of type i32, and it returns a value of i32. This means that a and b are both 32 integers. This means that both the arguments a and b to our bigger() function are 32-bit integers.

[0:47] The instructions in the comments tell us to complete this function to return the bigger number. We cannot use another function call which, in this case, I'll let you know that there is a max call in the Rust library. We also cannot use additional variables.

[1:04] Let's say if a > b, return a, else return b. Note that this works. Also note that we've used implicit return values because this is the last statement in our function, and thus, these are the last values encountered. We can also be explicit about this and write the return statements explicitly.

egghead
egghead
~ 36 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today