Start learning free

LESSON 69 OF 404 · CONDITIONAL STATEMENTS

If Statements in Go

Lesson

An if statement lets a program run code only when a condition is true.

In Go, the condition is written after if, and the body is wrapped in curly braces:

passed := true

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

You can add else to run different code when the condition is false:

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

Assignment
Follow the Coding Tutorial and print the correct message based on passed.


STEP 1 OF 2
    Ctrl + Enter to check