如何枚举Objective-C中的枚举? [重复]

时间:2022-09-07 09:38:12

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?

我如何枚举枚举?

1 个解决方案

#1


6  

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...
}

#1


6  

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...
}