Naresh Reddy M Naresh Reddy M - 3 days ago 5
iOS Question

Using logical operators(OR/AND,...) in iOS

I'm a newbie to programming,
I need to validate a couple of expressions in an if condition and when both of them returns true then only need to do some work.

I know i can do that by using logical operators,But i don't have clear idea about how the logical operators works.

Any help on this would be really appreciated.

Thanks in-advance.

Answer

Use of logical operators is best , multiple conditions.

for example

int firstValue=10; int sencondValue=16;

// OR operator , retursn TRUE is any of given condtion is true.
if (firstValue==10 || sencondValue==13 || firstValue>=5) {
    NSLog(@"True");
}
else
{

NSLog(@"False");


}
//above are 3 condtions in one statement , if any condition is true , result is true

// AND operator , retursn TRUE is all of given condtion are true  and flase if any on the given conditions are false.

if (firstValue==10 && sencondValue==13 && firstValue>=5) {
    NSLog(@"True");
}
else
{

    NSLog(@"False");


}
Comments