package mainimport "fmt"func main() {//一楼num := 1switch num { //switch后面写的是变量本身case 1:fmt.Printf("按下的是%d", num)case 2:fmt.Printf("按下的是%d", num)case 3:fmt.Printf("按下的是%d", num)case 4:fmt.Printf("按下的是%d", num)}}

其他特殊情况的default:
package mainimport "fmt"func main() {//一楼num := 0switch num { //switch后面写的是变量本身case 1:fmt.Println("按下的是", num)case 2:fmt.Println("按下的是", num)case 3:fmt.Println("按下的是", num)case 4:fmt.Println("按下的是", num)default:fmt.Println("你在瞎按!!!!!")}}

你会发现,跟其他语言不同,因为少了一个break关键字。
go语言保留了break关键字,跳出switch语言,不写,默认就包含。
再来看看另外一个go语言的关键字,fallthrough
fallthrough的意思就是不跳出switch语句,相当于没有写break。
如下图所示:
package mainimport "fmt"func main() {var num intfmt.Printf("请输入楼层数:")fmt.Scan(&num)//一楼switch num { //switch后面写的是变量本身case 1:fmt.Println("按下的是1楼")fallthroughcase 2:fmt.Println("按下的是2楼")fallthroughcase 3:fmt.Println("按下的是3楼")fallthroughcase 4:fmt.Println("按下的是4楼")fallthroughdefault:fmt.Println("你在瞎按!!!!!")}}

所以,fallthrough关键字的作用就是不跳出switch语句,后面的无条件执行。
