Conditions with `when`

Understand Kotlin's `when` construct and best practices of using `if` vs `when`.

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 1000+ tech skills courses.