-
Notifications
You must be signed in to change notification settings - Fork 0
Iota
Andrew Gerrand edited this page Dec 10, 2014
·
4 revisions
Go's iota
identifier is used in in const
declarations to simplify definitions of incrementing numbers. Because it can be used in expressions, it provides a generality beyond that of simple enumerations.
The values of iota start at zero within each const block and increment by one each time it is seen. This can be combined with the constant shorthand (leaving out everything after the constant name) to very concisely define related constants.
Iota: http://golang.org/doc/go_spec.html#Iota
Constant declarations: http://golang.org/doc/go_spec.html#Constant_declarations
The official spec has two great examples:
http://golang.org/doc/go_spec.html#Iota
Here's one from Effective Go:
type ByteSize float64
const (
_ = iota // ignore first value by assigning to blank identifier
KB ByteSize = 1<<(10*iota)
MB
GB
TB
PB
EB
ZB
YB
)
- Home
- Getting started with Go
- Working with Go
- Learning more about Go
- The Go Community
- Using the Go toolchain
- Additional Go Programming Wikis
- Online Services that work with Go
- Troubleshooting Go Programs in Production
- Contributing to the Go Project
- Platform Specific Information
- Release Specific Information