I like switch in Go.
func main() {
all := []string{"Denver", "London", "NY", "SF"}
for _, city := range all {
switch city {
case "Denver":
// code for Denver
fmt.Println("Denver")
case "London", "SF": // London OR SF the same logic
// code for London/SF
fmt.Println("London/SF")
case "NY":
// code for NY
fmt.Println("NY")
default:
// code default
fmt.Println("default")
}
}
}
Very easy to use, we just create cases and what to do by default: