How to use switch in Go language
Today, I will talk to you about how to use switch in the Go language, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something from this article.
Param: = "1" / / switch in the go language can put multiple conditions with the same results in the same case block, and each case block is independent. There is no need for break switch param {case "1", "2", "3": fmt.Println. 3 ") case" 4 "," 5 "," 6 ": fmt.Println (" here is 4 case 5)} / / but in order to support code migration, the Go language has added fallthrough to support the penetration of switch param {case "1", "2", "3": fmt.Println ("here is 1Magne2"). 3 ") fallthrough case" 4 "," 5 "," 6 ": fmt.Println (" here is 4Magazine 6 ")} param2: = 1 / / go language supports the use of judgment expressions in case expressions At this time, switch will no longer follow the decision variable switch {case param2 > 10: fmt.Println ("numbers greater than 10") case param2