Created
September 12, 2019 14:51
-
-
Save hosszukalman/d28a021997481807e3ee16bd8e35f2a3 to your computer and use it in GitHub Desktop.
Golang's iota
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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