Conclusion

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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
Download course materials from Github
Previous: Demo Next: Quiz: Leverage When Expressions