Rust TutorialLesson 12Free preview
Rust If..Else
This lesson is part of Rust · All levels
Summary
This lesson discusses branching using constructions if, else if, and else in Rust. Interestingly, in Rust 'if' is an expression that yields value, so it can be used directly to set the value of a variable. This ability makes conditional codes more concise and declarative.
Key points
- Conditional statements using 'if', 'else if', and 'else'
- The condition does not require a regular parenthesis around it
- Since 'if' is an expression, the result can be directly stored in the variable.
- Each branch on the expression if must return a consistent data type
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.