Start learning free

LESSON 90 OF 671 · CONDITIONAL STATEMENTS

Combining Logical Operators in Go

Lesson

Logical operators can be combined to express more complex rules.

Use parentheses to make the grouping clear:

specialStudent := false
age := 23

if specialStudent || (age >= 18 && age <= 30) {
    fmt.Println("Let him in!")
} else {
    fmt.Println("Not allowed")
}

This allows entry if the student is special, or if the age is between 18 and 30 inclusive.

Assignment
Combine || and && to check the entry rule.


STEP 1 OF 2
    Ctrl + Enter to check