golang iota
寫法一:
const (
a = iota + 2020
b = iota + 2020
c = iota + 2020
d = iota + 2020
)
寫法二:
const (
a = iota + 2020
b
c
d
)
寫法一和寫法二的輸出結果會是一樣的
iota 在新的const()裡面會重置
印出來的結果會是
0
1
2
0
1
2
package main
import (
"fmt"
)
const (
a = iota
b
c
)
const (
d = iota
e
f
)
func main() {
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
fmt.Println(d)
fmt.Println(e)
fmt.Println(f)
}