If and Else
Learn how to make decisions in Kotlin using if, else if and else.
Kotlin Code
Study the example and understand each part.
fun main() {
val marks = 78
if (marks >= 70) {
println("Grade A")
} else if (marks >= 60) {
println("Grade B")
} else if (marks >= 50) {
println("Grade C")
} else {
println("Grade D")
}
}
Kotlin is commonly developed using Android Studio or IntelliJ IDEA. These examples can be used as a foundation for Android application development.
Key Concept
Kotlin's if expression can return a value, making decision-making concise.
Expected Output / Result
Grade A
Finished this lesson?
Mark it complete to update your course progress.