Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use switch case in go

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use switch case in go. It is very detailed and has a certain reference value. Friends who are interested must finish it!

You can have a case with several parameters:

Var I = 0switch I {case 0,1: fmt.Println ("1") case 2:fmt.Println ("2") default: fmt.Println ("def")}

Break effect is available by default. To cancel, add fallthrough:

Var I = 0switch I {case 0: fallthroughcase 1: fmt.Println ("1") case 2:fmt.Println ("2") default: fmt.Println ("def")}

Case can also be an expression:

Var I = 0switch {case I > 0 & & I

< 10: fmt.Println("i >

0 and i

< 10")case i >

10 & & I

< 20:fmt.Println("i >

10 and I < 20 ") default: fmt.Println (" def ")}

Note: the switch case of go has break by default. If you don't need break, add fallthrough**~~.

The above is all the contents of the article "how to use switch case in go". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report