control

val size = 10
val bucket = if (size > 100) "big" else if (size > 4) "small" else "tiny"

if is an expression It returns a value That makes a lot of Java boilerplate disappear

when

val str = when (month) {
    1 -> "January"
    2 -> "February"
    3 -> "March"
    else -> "Some other month"
}

No fall through Each branch returns a value when can replace both switch and if chains

loops

for (i in 0 until 10) {
    println(i)
}

Ranges are readable until excludes the end .. includes it

enhanced for

for (item in items) {
    println(item)
}

Iterates any iterable Use indices when you need the position

Next

Functions in 05 functions

Test this in your lab first

Posted