Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Control structures
If
https://kotlinlang.org/docs/reference/control-flow.html#if-expression
The classic if
is revised, it is an expression :
When
https://kotlinlang.org/docs/reference/control-flow.html#when-expression
Kotlin doesn't have a switch
keyword, it replaces it with a powerful when
expression, similar to pattern matching :
For
https://kotlinlang.org/docs/reference/control-flow.html#for-loops
For loops are implemented as foreach
loops, using in
keyword :
Ranges
https://kotlinlang.org/docs/reference/ranges.html
Using rangeTo
functions ranges can be defined for any comparable type.
The ..
operator is used to define ranges, in
and !in
to check if a value is included in a range or to iterate over a range (for integral type).
downTo
, step
and until
can be used to revert the range, change the progression step or exclude the last value.