Every adventurer must make decisions. In Go, if runs a block only when its condition is true, and else covers the other case:
if gold >= 100 {
fmt.Println("You can afford the sword.")
} else {
fmt.Println("Keep saving, adventurer.")
}
Conditions use comparison operators (==, !=, <, >, <=, >=) and can be combined with && (and), || (or), and ! (not). You can chain checks with else if.
Your Quest
The hero’s health is 30. Print Retreat! if health is below 50, otherwise print Charge!.
Expected output:
Retreat!
Hint
if health < 50 { ... } else { ... } โ put a fmt.Println in each branch.