Tomblasta
Tomblasta

Reputation: 2161

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

Upvotes: 31

Views: 78423

Answers (2)

user3400223
user3400223

Reputation: 768

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

Upvotes: 56

Connor
Connor

Reputation: 64644

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.

Upvotes: 8

Related Questions