Skip to content

Instantly share code, notes, and snippets.

@hosszukalman
Created September 12, 2019 14:51
Show Gist options
  • Save hosszukalman/d28a021997481807e3ee16bd8e35f2a3 to your computer and use it in GitHub Desktop.
Save hosszukalman/d28a021997481807e3ee16bd8e35f2a3 to your computer and use it in GitHub Desktop.
Golang's iota
package main
import (
"fmt"
)
const zero = iota // Iota is the first in decalration scope, so it should be 0
const (
a = -2
b = -9
c = 19
d = iota // Iota is the fourth, so it should be 3.
)
const (
e = 13
f = 8
g = iota // Iota is the third, so it should be 2.
)
const (
h = iota // 0
i = iota // 1 We can use iota string, it will increment the integer.
j // 2 We can leave iota string, it's equivalent.
k // 3
)
const (
s = "string"
t = iota // 1
)
func main() {
fmt.Println("Hello, playground")
fmt.Println(zero)
fmt.Println(a, b, c, d)
fmt.Println(e, f, g)
fmt.Println(h, i, j, k)
fmt.Println(s, t)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment