Start learning free

LESSON 70 OF 404 · CONDITIONAL STATEMENTS

If-Else Statements in Go

Lesson

An else block runs when the if condition is false.

passed := false

if passed {
    fmt.Println("Passed the test")
} else {
    fmt.Println("Failed the test")
}

Only one branch runs: the if body when passed is true, otherwise the else body.

Assignment
Complete the else branch so the failed message is printed when passed is false.


STEP 1 OF 1
    Ctrl + Enter to check