Skip to content Skip to sidebar Skip to footer

Swift If Or/and Statement Like Python

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

Solution 1:

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

Solution 2:

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.

Post a Comment for "Swift If Or/and Statement Like Python"