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
ififThe 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.")
}
}