When It’s Time to Use when

Kotlin doesn’t have switch; instead it has when, and that comes in different flavors: as expression and as statement.

when as an expression

Here’s an implementation of the function to determine if a cell will be alive in the next generation in Conway’s Game of Life.

Get hands-on with 1200+ tech skills courses.