Control Flow
If, while and do-while expression is the same for Kotlin.
When:
When expression replaces switch on Java. This is its most basic form:

You can include many cases in a branch like this:

You can use arbitrary expressions, not only constant.
You can use a range of values:

You can use is or !is to check if a value is of a particular type:

For:
There’s no a real for loop in Kotlin. What I mean the for loop in Kotlin is like a for-each in Java, it iterate objects that provide an iterator. So, let’s see the structure:
![]()
You can iterate in a range too:

