Go Basics

Go Conditions

Description

Go supports `if`, `else if`, and `else`. The condition does not strictly require parentheses, but the braces `{}` are mandatory.

Pros & Cons

✅ Pros

  • Clear Scoping: `if` can simulate a short statement before condition.

❌ Cons

  • None.

When to Use

Branching logic.

Example

Basic If-Else.

x := 10

if x < 0 {
    fmt.Println("Negative")
} else if x == 0 {
    fmt.Println("Zero")
} else {
    fmt.Println("Positive")
}

Best Practices

The braces are mandatory, even for one-line blocks.

← Bitwise OperatorsGo Switch →