The when Statement

Learn about when statement and enhance the code readability.

We'll cover the following

The when statement is an alternative to if-else-if. In every branch, we specify a predicate and the body that should be executed if this predicate returns true (and previous predicates did not). So, it works just like if-else-if but should be preferred because its syntax is better suited for multiple conditions.

Get hands-on with 1200+ tech skills courses.