大家好,又见面了,我是你们的朋友全栈君。
Go语言计算iota的方法如下代码,iota主要用作枚举
package main
import "fmt"
//iota理解,无左移动情况,常量=iota,则下面的常量从 0开始每次都增加一。
//如果常量定义为含有左移 num << iota 则, 下面的值以当前const最后一个带有iota的数值为准,左移动iota即乘以2的iota次方。iota每次增加一。如下
const (
Sunday = 5 << iota=0
monday // =5 <<1
Thuesday // =5 <<2
Wednesday // =5<<3
)
const (
one = 3 //<< iota
two //3 <<1 =3 *2^1 =6
three // 3 <<2 3*2^2 = 12
)
const (
text = 5 << iota // 5 * 2^0 =5
text2 = 10 << iota // 10 * 2^1 =10
text3 // 10 * 2^2 = 40
text4 // 10 * 2^3 = 80
)
func main() {
fmt.Println(one, two, three)
}
转载于:https://my.oschina.net/loveleaf/blog/2218560
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107287.html原文链接:https://javaforall.net