A generic switch. Cases are evaluated top to bottom, stopping when a match is found. No `break` is needed (automatic break). Use `fallthrough` to force continuation.
Multi-way branching.
Switch on value and type.
// Basic Switch
os := "darwin"
switch os {
case "darwin":
fmt.Println("OS X")
case "linux":
fmt.Println("Linux")
default:
fmt.Println("Windows?")
}
// Tagless Switch (like if-else)
t := 10
switch {
case t < 12:
fmt.Println("Morning")
case t < 17:
fmt.Println("Afternoon")
}
Use switch for clearer readability when checking multiple conditions.