Created
March 30, 2012 13:41
-
-
Save jpoehls/2251637 to your computer and use it in GitHub Desktop.
Duplicate const values in #golang with 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" | |
// iota is reset to 0 at every const declaration | |
const ( | |
Zero = iota // within a const declaration, iota is incremented for every line | |
One // default value is set to iota, which is now 1 | |
Two = 2 // exlicitly set to 2 | |
TwoAgain // default value is set to iota, which is now 2 creating a duplicate 2 | |
) | |
func main() { | |
fmt.Printf("Zero: %d\n", Zero) | |
fmt.Printf("One: %d\n", One) | |
fmt.Printf("Two: %d\n", Two) | |
fmt.Printf("TwoAgain: %d\n", TwoAgain) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment