Programming in Kotlin: Fundamentals

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

Part 1: Use Data Types & Operations

7. Branch with If Expressions & Scopes

Lesson Complete

Play Next Lesson
Save for later
About this episode
See versions
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 6. Combine Logical Operators Next episode: 8. Challenge: Practice If Expressions & Boolean Logic

This video was last updated on Aug 9 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

At this point, you should feel pretty good about working with logical operators. You’ve seen how combining them can produce a true or false value. But what if you wanted to set a value based on the result of our logical operators? Often times, you’ll want to set a variable based on a condition.

// Starter code
val chrisGrade = 49
val meritAwardGrade = 90
var message
var message: String
val chrisHasPerfectAttendance = true
val chrisIsMeritStudent = chrisHasPerfectAttendance && chrisGrade > meritAwardGrade
if (chrisIsMeritStudent) {
    message = "Congratulations"
else {
    message = "Keep studying"
val samGrade = 99
val betterStudent 
val betterStudent = if (samGrade > chrisGrade) "Sam" else "Chris"
val betterStudent = if (samGrade > chrisGrade) {
} else if (samGrade < chrisGrade) {
} else {
    "They have equal grades!!!"