In the Go Specification, near the end of the section on constant declarations, it assigns the value iota to a const
.
Iota
is the predeclared identifier.
package main
import (
"fmt"
)
const (
a = iota
b = iota
c = iota
)
func main() {
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
fmt.Printf("%T\n", a)
fmt.Printf("%T\n", b)
fmt.Printf("%T\n", c)
}
You can see this gives us the auto incrementing values, 0, 1, 2. A shorthand for declaring auto incremented constant values is to just set the first one to iota
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)
}
You can see the auto incrementing restarts in each new group of const declarations.