Go · Stage 2 – Doing Things with Values · Lesson 17 of 64

Logical Operators

Combine or reverse boolean values with Go logical operators.

Go code

allowed := true && false
fmt.Println(allowed)
Line-by-line explanation
  1. AND requires both sides to be true.
  2. The right side is false.
  3. Allowed becomes false.
Expected output
false

This is the expected result.

OR is true when at least one side is true. NOT reverses one boolean.

Go code

offline := !true
fmt.Println(offline)
Line-by-line explanation
  1. The exclamation mark means NOT.
  2. It reverses true to false.
  3. The result is displayed.
Expected output
false

This is the expected result.