Start learning free

LESSON 88 OF 671 · CONDITIONAL STATEMENTS

Or Operator in Go

Lesson

The Go || operator means or.

A condition using || is true when at least one side is true:

weather := "sunny"
temperature := 90

if weather != "sunny" || temperature <= 85 {
    fmt.Println("Learning to code")
} else {
    fmt.Println("Going to the beach")
}

Here neither "bad beach condition" is true, so the else branch runs.

Assignment
Use || to check whether either condition keeps us from the beach.


STEP 1 OF 2
    Ctrl + Enter to check