Start learning free

LESSON 85 OF 671 · CONDITIONAL STATEMENTS

And Operator in Go

Lesson

The Go && operator means and.

A condition using && is true only when both sides are true:

weather := "rainy"
temperature := 90

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

Here the temperature is high enough, but the weather is not sunny, so the whole condition is false.

Assignment
Use && to check both beach conditions.


STEP 1 OF 2
    Ctrl + Enter to check