In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Go language process control of what is the conditional statement, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
What is go?
Golang is a compiled language that compiles code into machine code, and the compiled binaries can be deployed directly to the target machine without additional dependencies, so golang outperforms other interpretative languages and can use goroutine to achieve concurrency in golang. It provides a very elegant goroutine scheduler system that can easily generate millions of goroutine.
Process control is mainly used to set the order of calculation execution and establish the logical structure of the program. The flow control of Go language is similar to that of PHP, and supports the following process control statements:
Conditional statement: for conditional judgment, the corresponding keywords are if, else and else if
Select statement: for branch selection, the corresponding keywords are switch, case and select (for channels, which will be mentioned later in the description of the protocol)
Loop statement: for loop iteration, the corresponding keywords are for and range
Jump statement: used for code jump, the corresponding keyword is goto.
In the actual use, often according to the specific business logic, flexible combination of the above control language to achieve the corresponding functions.
Next, let's briefly introduce the usage of various process control statements, starting with conditional statements. An example template for conditional statements is as follows:
/ / ifif condition {/ / do something}
/ / if...else...if condition {/ / do something} else {/ / do something}
/ / if...else if...else...if condition1 {/ / do something} else if condition2 {/ / do something else} else {/ / catch-all or default}
Students with basic knowledge of other programming languages are easy to understand. The sample code for a simple conditional statement is as follows:
Score: = 100if score > 90 {fmt.Println ("Grade: a")} else if score > 80 {fmt.Println ("Grade: B")} else if score > 70 {fmt.Println ("Grade: C")} else if score > 60 {fmt.Println ("Grade: d")} else {fmt.Println ("Grade: F")}
This code can be used to print the level corresponding to a specified score.
Compared with PHP, with regard to conditional statements in Go language, you should pay attention to the following points:
Conditional statements do not need to use parentheses to include conditions ()
Curly braces {} must exist no matter how many statements are in the body of the statement.
Left curly braces {must be on the same line as if or else
After if, before conditional statements, you can add variable initialization statements, using interval, for example, the above code can write if score: = 100; score > 90 {
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.