Is there a way to to do and/or in an if statement in swift. eg/
if a > 0 and i == j or f < 3:
//do something
can we do that in swift?
Thanks in advance
If both the operands are non-zero, then the condition becomes true. (A && B) is false. || Called Logical OR Operator.
Swift supports the following comparison operators: Equal to ( a == b ) Not equal to ( a !=
In Swift, we use the guard statement to transfer program control out of scope when certain conditions are not met. The guard statement is similar to the if statement with one major difference. The if statement runs when a certain condition is met. However, the guard statement runs when a certain condition is not met.
You can use
&&
for logical and
||
for logical or
so you can do
if a > 0 && i == j || f < 3 {
...
}
see here https://developer.apple.com/library/ios/documentation/swift/conceptual/Swift_Programming_Language/BasicOperators.html
Yes.
if (a > 0 && i == j || f < 3){
//do something
}
You should probably do some reading on the basics of Swift before jumping in. If statements are covered in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With