bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Go/Go Tutorial
Go•Go Tutorial

Go if 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