Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #122 Declare an enumeration

Create an enumerated type Suit with 4 possible values SPADES, HEARTS, DIAMONDS, CLUBS.

type Suit int

const (
  Spades Suit = iota
  Hearts
  Diamonds
  Clubs
)

Go doesn't have enumerations.
The 4 constants have values 0, 1, 2, 3.
type Suit is (Spades, Hearts, Diamonds, Clubs);

New implementation...
< >
programming-idioms.org