When you have one value and many possible branches, a chain of else if gets noisy. Go’s switch is cleaner:
switch weather {
case "sunny":
fmt.Println("A fine day to adventure.")
case "stormy":
fmt.Println("Best stay at the inn.")
default:
fmt.Println("Weather unknown.")
}
Unlike many languages, Go does not fall through to the next case automatically — each case stops on its own, so you rarely need break.
Your Quest
Switch on class: print Casts a fireball! for "Mage", Swings a sword! for "Warrior", and Waits. for anything else.
Expected output:
Casts a fireball!
Hint
Use switch class { case "Mage": ...; case "Warrior": ...; default: ... }.