As for your question, where did you compare 50 values.
Create an NSMutableArray consisting of these 50 variables ... then use this code.
Use this code:
if ([myArray containsObject:i]) {
It works like a charm!
If you want to check each value separately, you can use a while loop or a for loop:
n = 0; while (n<49) { if (n==[myArray objectAtIndex:n]) { //OR statement returned true for one of the 50 objects... } }
Parts below are for others who need different answers to this question:
There may be ways to shorten your conditional statement if we still have the code ... as for shortening only the "OR" part, I'm not sure how ...
But something like:
if ((i==x)||(i==y)) { string=@ "hello"; }
can be:
string = ((i==x)||(i==y)) ? @"hello";
or ... something like:
if ((i==x)||(i==y)) { string=@ "hello"; } else { string=@ "goodbye"; }
can be:
string = ((i==x)||(i==y)) ? @"hello" : @"goodbye";
Since I often use conditional operators with numerical values, I often use a shortcut where, if the conditional statement is true, it is equivalent to 1, whereas if it is false, it is equivalent to 0, because of this I can say things like
myNumber = ((i==x)||(i==y))*(z+w);
If I equal x or y, it will return true (which is equal to "1"), which will return 1 * (z + w) or (z + w), but if the condition is false, it returns "0", returns 0 * (z + w) or 0.
Final notes: * There may be mathematical ways to represent the hat function that returns the desired results you want ... for example, if x = -2 and y = 2, than instead of checking if I == x or I == y, just check if abs (i) == y (* abs is the absolute value)