Possible Duplicate:
looping through enum values
Suppose we're dealing with a deck of cards
typedef enum {
HEARTS, CLUBS, DIAMONDS, SPADES, SUIT_NOT_DEFINED
} Suit;
How can i enumerate over an enum?
Possible Duplicate:
looping through enum values
Suppose we're dealing with a deck of cards
typedef enum {
HEARTS, CLUBS, DIAMONDS, SPADES, SUIT_NOT_DEFINED
} Suit;
How can i enumerate over an enum?
You can use the lower bound of the enum
as the starting point and test that against the upper bound in the loop condition:
for(int i = HEARTS; i < SUIT_NOT_DEFINED; ++i) {
//do something with i...
}