Kotlin TutorialLesson 12Free preview
Kotlin If...Else
This lesson is part of Kotlin · All levels
Summary
This lesson discusses conditional branching using 'if', 'else if', and 'else' in Kotlin. Interestingly, just like in Rust, the 'if' in Kotlin can act as an expression that yields a return value. This eliminates the need for traditional ternary operators.
Key points
- Conditional statements using the keywords 'if' and 'else'
- In Kotlin, 'if' is an expression that can return a value
- The use of 'if' as an expression replaces the function of the ternary operator (?:)
- If used as an expression, the 'else' branch is mandatory
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.