Keyword

Go if keyword

Executes a block when the condition is true. The optional initializer is scoped to the complete if statement, including its else branches. Go requires braces and a boolean condition. Example prints eligible.

Formal Syntax & Structure

go syntaxgo
if [simpleStatement;] booleanExpression { statements }

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  if score := 82; score >= 70 {    fmt.Println("eligible")  }}
Go Reference