Quicker if-statement: if `variable` is “value” or “value”

前端 未结 7 2134
感情败类
感情败类 2020-12-18 15:44

How can you compare against multiple possibilities in one argument?

Example:

if ((integer == 2) || (integer == 5))

if ((string == \"hello\") || (str         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 16:14

    First of all string comparasion doesn't work that way in C, I know nothing about objective-c, thought.

    For the comparison against compile time integral constants, in C you have the switch statement:

    switch (integer) {
    case 2: ;
    case 5: ;
       /* do stuff here */
    }
    

提交回复
热议问题