/* * Illustration of the switch statement in Go * Somewhat different from Java and C. */ package main import "fmt" func taggedSwitchInt(x int) { switch x { case 1: fmt.Printf("xx == 1\n") case 2: fmt.Printf("xx == 2\n") case 3,4: fmt.Printf("xx is 3 or 4\n") default: fmt.Printf("x not 1 or 2 or 3 or 4 %d\n", x) } } // This version does the same thing as the tagged switch. // a tagless switch is really just a chained if-then-else func taglessSwitchInt(xx int) { switch { case xx==1: fmt.Printf("xx == 1\n") case xx==2: fmt.Printf("xx == 2\n") case xx==3||xx==4: fmt.Printf("xx is 3 or 4\n") default: fmt.Printf("x not 1 or 2 or 3 or 4 %d\n", xx) } } func main() { for i:=0; i<5; i++ { taggedSwitchInt(i) taglessSwitchInt(i) } }