在使用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") }
本文详细介绍了Go语言中switch结构的使用方法及注意事项,包括左花括号的位置、条件表达式的灵活性、多个结果选项的支持、fallthrough关键字的作用等。
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") }

被折叠的 条评论
为什么被折叠?