Puzzle 25 Explanation: Go iota
Understand how iota works in Go.
We'll cover the following...
We'll cover the following...
Try it yourself
Try executing the code below to see the result.
Go (1.16.5)
package mainimport ("fmt")const (Read = 1 << iotaWriteExecute)func main() {fmt.Println(Execute)}
Explanation
In Go, iota
is an enumerated type. It can be used inside a const
declaration. For each constant in the same group, iota
grows by one. If we specify an operation on iota
— for ...