Start learning free

LESSON 89 OF 671 · CONDITIONAL STATEMENTS

Not Operator in Go

Lesson

The Go ! operator means not. It flips a boolean value.

isSunny := true

if !isSunny {
    fmt.Println("Learning to code")
} else {
    fmt.Println("Going to the beach")
}

Since isSunny is true, !isSunny is false, so the else branch runs.

Assignment
Use ! to check when it is not sunny.


STEP 1 OF 2
    Ctrl + Enter to check