In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to use if sentences in go language". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
If statements look the same as in C or Java, except without () (or even forcing them not to be used), and {} is required.
The code is as follows:
Package mainimport ("fmt"math") func sqrt (x float64) string {if x
< 0 { return sqrt(-x) + "i" } return fmt.Sprint(math.Sqrt(x))}func main() { fmt.Println(sqrt(2), sqrt(-4))} 跟 for 一样,if 语句可以在条件之前执行一个简单的语句。 由这个语句定义的变量的作用域仅在 if 范围之内。 (在最后的 return 语句处使用 v 看看。) package mainimport ( "fmt" "math")func pow(x, n, lim float64) float64 { if v := math.Pow(x, n); v < lim { return v } return lim}func main() { fmt.Println( pow(3, 2, 10), pow(3, 3, 20), )} 在 if 的简单语句处定义的变量同样可以在任何对应的 else 块中使用。 package mainimport ( "fmt" "math")func pow(x, n, lim float64) float64 { if v := math.Pow(x, n); v < lim { return v } else { fmt.Printf("%g >=% g\ n ", v, lim)} / / can't use v here, so return lim} func main () {fmt.Println (pow (3,2,10), pow (3,3,20),)}" how to use if statements in go "ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.