Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enumerate over enum in Objective-C? [duplicate]

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?

like image 669
James Raitsev Avatar asked Dec 06 '11 03:12

James Raitsev


1 Answers

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...
}
like image 83
Jacob Relkin Avatar answered Oct 23 '22 04:10

Jacob Relkin