[Go] Constant
iota
- Generate a set of related but distinct constants
- Often represents a property which has several distinct possible values
- Dyas of the week
- Months of the year
package main
import "fmt"
func main() {
type Grades int
const (
A Grades = iota
B
C
D
E
)
fmt.Println(A) // 0
fmt.Println(B) // 1
}
To skip zero
package main
import "fmt"
func main() {
type Grades int
const (
_ Grades = iota
A
B
C
D
E
)
fmt.Println(A) // 1
fmt.Println(B) // 2
}