In this lesson you learned about the following topics:
the when keyword,
differences between the when and if statements,
the statements and expressions,
differences between exhaustive and non-exhaustive when statements,
The when statement is a more flexible way of branching than if. It is especially useful when you have
multiple conditions to check. The syntax of a when is more compact and easier to read than
if. It can be used as a statement or an expression as well. It means that it can return a
value unlike a statement which does not return anything and has only side effects. Note that the when
expression has to be exhaustive. It means that it has to return a value from every branch. In most
of the cases, it means, there is an else branch required.
That is all for this lesson. In the next one, you will learn about the loops and how to repeat your
code. See you there!
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Demo
Next: Quiz: Leverage When Expressions
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.