bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Go/Go Tutorial
Go•Go Tutorial

Go if else Statement

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Go if else Statement?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

// code to be executed ___ condition is true
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Use the else statement to specify a block of code to be executed if the condition is false .
Using The if else Statement
The else Statement

The else Statement

Use the else statement to specify a block of code to be executed if the condition is false .

Syntax

if
condition {
 // code to be executed if condition is true
} else {
// code to be executed if condition is false
}

Using The if else Statement

if
if

The brackets in the else statement should be like } else { :

Example

package main
import ("fmt")
func main() {
  temperature := 14
  if (temperature > 15) {
    fmt.Println("It is warm out there.")
  }
// this raises an error
else {
  fmt.Println("It is cold out there.")
}
}

Previous

Go if statement

Next

Go else if Statement