go if 便捷语句

it2022-05-05  109

之前使用java  C#没这么用过.

绝对新技能 if v := math.Pow(x, n); v < lim {

跟 for 一样,`if` 语句可以在条件之前执行一个简单的语句。

由这个语句定义的变量的作用域仅在 if 范围之内。

 

package main import (     "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),     ) }  

go语言开发交流qq群 857263711

保持进步希望每个人都能找到自己喜欢的方式生活、工作。

转载于:https://www.cnblogs.com/songhuan999999/p/11188963.html


最新回复(0)