Branching: Switch
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Print("Go runs on ")
os := runtime.GOOS
switch os {
case "darwin":
fmt.Println("OS X.")
case "linux":
fmt.Println("Linux.")
default:
fmt.Printf("%s.\n", os)
}
}
// Go runs on LinuxSwitch with shorthand expression
Switch without condition
Switch allows multiple expressions
Last updated