← Back to Scala Course | Chapter 3: Operators & Expressions | Lesson 3 of 7

Logical Operators

In this page:

  1. Logical Operators

Logical Operators

Logical operators combine Boolean expressions: && (AND), || (OR), and ! (NOT). && and || short-circuit -- if the left side already determines the result, the right side is never evaluated. This matters when the right side has side effects or could throw.

Note: Short-circuiting lets you safely write if (list.nonEmpty && list.head > 0) without risking an error on an empty list.

Example: Logical Operators

markup
object Main extends App {
  val isLoggedIn = true
  val isAdmin = false

  println(isLoggedIn && isAdmin)
  println(isLoggedIn || isAdmin)
  println(!isAdmin)
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.