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...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With