Keyword
Go else keyword
Runs an alternate branch when the preceding if condition is false. Place else on the same line as the preceding closing brace in formatted Go, to avoid semicolon insertion. Example prints closed.
Formal Syntax & Structure
go syntaxgo
if condition { statements } else { statements } | if condition { statements } else if condition { statements }Working Example
Example Snippetgo
package main
import "fmt"
func main() { open := false if open { fmt.Println("open") } else { fmt.Println("closed") }}