Module 01 Β· Kotlin Basics β Lesson 5 of 5 Β· ~14 min
Making Decisions
if / else as an expression
Programs constantly choose between paths. if runs a block of code only when a condition β an expression whose type is Boolean β is true. else provides the block to run when it isn't.
Conditions usually come from comparison operators, each producing a Boolean:
==equal (two equals signs! a single=assigns)!=not equal<>less / greater than<=>=less / greater than or equal
Kotlin's if has a superpower Swift's doesn't: it's an expression, meaning it can produce a value directly β val label = if (rating >= 4.5) "Top-rated" else "Solid" skips the temporary variable entirely.