Conditions with `when`
Understand Kotlin's `when` construct and best practices of using `if` vs `when`.
We'll cover the following
Conditions Using when
#
You can use when
conditions to define different behaviors for a given set of distinct values. This is typically more concise than writing cascades of if
-else if
conditions. For instance, you can replace the if
condition above with a when
condition to save around 30% of the lines of code in this example:
Get hands-on with 1400+ tech skills courses.