更快的if语句:如果`variable`是"价值"或QUOT;价值" [英] Quicker if-statement: if `variable` is "value" or "value"
本文介绍了更快的if语句:如果`variable`是"价值"或QUOT;价值"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你怎么能在一个参数比较的多种可能性?
例如:
IF((整数== 2)||(整数== 5))如果((字符串==你好)||(字符串==小车))
将节省我很多code,如果你可以写这样的:
如果(整数==(2 || 5))如果(字符串==(你好||多利))
解决方案
所有的字符串比较讨论不起作用这种方式在C首先,我什么都不知道的Objective-C,思想。
有关反编译的时候整型常量的比较,在C你有switch语句:
开关(整数){
案例2:;
案例5:;
/ *做的东西在这里* /
}
How can you compare against multiple possibilities in one argument?
Example:
if ((integer == 2) || (integer == 5))
if ((string == "hello") || (string == "dolly))
Would save me a lot of code if you could write that like this:
if (integer == (2 || 5))
if (string == ("hello" || "dolly"))
解决方案
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 */
}
这篇关于更快的if语句:如果`variable`是"价值"或QUOT;价值"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文