×

go · level 1 · unit 4 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

An if runs code only when its is true.

Picture a fork in the path with a sign: Is it Saturday? An if asks a condition like that. If the answer is true, Go runs the lines inside. If it is false, Go walks straight past.

To ask whether two values match, use two equals signs, ==. One = puts a value in a box. Every condition gives a bool: true or false.

The lines that belong to the if sit inside curly brackets, called a . The { goes at the end of the if line, never on a line of its own.

package main
import "fmt"
func main() {
	day := "Saturday"
	fmt.Println(day == "Saturday")
	if day == "Saturday" {
		fmt.Println("Pancakes for breakfast!")
	}
	fmt.Println("Time to get dressed.")
}

Lines after the closing } sit outside the if, so they run every time.