# Programming in Kotlin: Fundamentals

Aug 9 2022 · Kotlin 1.6, Android 12, IntelliJ IDEA CE 2022.1.3

## Part 2: Manage Control Flow

### Episode complete

Play next episode

Next

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

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

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

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

Unlock now

You learned how If/Else expressions are also a part of managing the control flow. Sometimes you have a lot of cases in such an expression, and the logic gets complicated, or just too long to cover with just if/else statements.

``````val age = 23
``````
``````when(age) {

}
``````
``````when(age) {
23 -> println("Close to a quarter century!")
25 -> println("Quarter century!")
else -> {
}
}
``````
``````when(age) {
in 0..12 -> println("Still a young human")
in 13..19 -> println("Teenager")
in 20..29 -> println("In your twenties")
in 30..39 -> println("In your thirties")
in 40..49 -> println("In your forties")
else -> println("You're a wise person :]")
}
``````
``````val message = when(age) {
in 0..12 -> "Still a young human"
in 13..19 -> "Teenager"
in 20..29 -> "In your twenties"
in 30..39 -> "In your thirties"
in 40..49 -> "In your forties"
else -> "You're a wise person :]"
}

println(message)
``````
``````val email = "mail@mail.com"
``````
``````when {
}
``````
``````when {
email.isEmpty() -> {
println("You need to choose an email!")
}
}
``````
``````when {
...

"@" !in email -> {
}
}
``````
``````when {
...

println("You need to choose a password!")
}

}
}
``````
``````when {
...

else -> {
println("Email length: \${email.length}, " +
}
}
``````
``````when {
email.isEmpty() -> println("You need to choose an email!")

"@" !in email -> println("Your email is invalid :[")