Learning Kotlin: Using ‘if’ Expressions

Another Learning Kotlin tutorial for beginners. Helping you learn Kotlin 1 small tutorial at a time.

In this video, you’ll learn how to use if expressions and how to use if for logical control flow.

// basic control flow using if/else
fun printGreeting(name:String) {
    if(name.isNotBlank()) {
        println("hello $name")
    } else {
        println("hey there!")

// Use 'if' as an expression in 
// a single expression function
fun getGreeting(age:Int) = if(age > 18) "hello" else "hey"

📚 Reference Documentation: https://kotlinlang.org/docs/reference/basic-syntax.html#using-conditional-expressions

I love to meet/talk/discuss and help where I can. If you want to chat or ask a question you can follow me on Twitter, YouTube, Instagram and Facebook.

Check Out My YouTube Channel

Categories: Learning Kotlin


Leave a Reply