Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Flow Control

Kotlin’s support for selecting between different execution paths is similar to what you’ve already seen in C & Python. However, one important difference is that these selection structures operate as expressions rather than statements, i.e., they yield values that can be assigned to a variable.

Iteration will also feel mostly familiar to you. Kotlin’s while loop is very much like C’s while loop, and its for loop is very similar to Python’s for loop. However, Kotlin also supports styles of iteration that are not found in those languages.

After completing this section, you will have a thorough understanding of how do selection and iteration in Kotlin. The other ways of affecting flow are covered in the sections on functions and error handling.