在使用switch结构时,我们需要注意以下几点:
示例
i := 0 switch i{ case 0: fmt.Printf("0") fallthrough case 1: fmt.Printf("1") case 2: fallthrough case 3: fmt.Printf("3") case 4, 5, 6: fmt.Printf("4, 5, 6") default: fmt.Printf("Default") }
i := 0 switch i{ case 0: fmt.Printf("0") fallthrough case 1: fmt.Printf("1") case 2: fallthrough case 3: fmt.Printf("3") case 4, 5, 6: fmt.Printf("4, 5, 6") default: fmt.Printf("Default") }