Programming in Kotlin: Fundamentals

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

Part 1: Use Data Types & Operations

6. Combine Logical Operators

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 5. Challenge: Booleans Next episode: 7. Branch with If Expressions & Scopes

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 kodeco.com Professional subscription.

In the previous set of episodes, you saw how you can work with Boolean values, and how you could use comparison operators such as less than, greater than, equal to and not equal to, to compare values to each other.

val passingGrade = 50
val studentGrade = 50
val chrisGrade = 49
val samGrade = 99
val studentPassed = studentGrade >= passingGrade
val chrisPassed = chrisGrade >= passingGrade
val samPassed = samGrade >= passingGrade
println(!samPassed)
println(!chrisPassed)
println(chrisPassed == false)
val catName = "Jaspurr"
println(!catName)
// val catName = "Jaspurr"
// println(!catName)
// AND Operator
// &&
val bothPassed = chrisPassed && samPassed
println(bothPassed)

Demo 2

The OR operator is two vertical lines, or pipes like this:

// OR Operator
// ||
val eitherPassed = chrisPassed || samPassed
println(eitherPassed)
val anyonePassed = chrisPassed || samPassed || studentPassed
println(anyonePassed)
val everyonePassed = chrisPassed && samPassed && studentPassed
println(everyonePassed)
val meritAwardGrade = 90
val samHasPerfectAttendance = true
val samIsMeritStudent = samHasPerfectAttendance && samGrade > meritAwardGrade
println(samIsMeritStudent)