Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use switch in Go language

Shulou Source: shulou.com Published: 2022-06-02 10:42:09 11月15日 Update

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

Tags: Language support content expression same between code variable multiple time more condition knowledge article result industry information information channel or channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia Apple Shulou Tech Info Linux