Tomblasta Tomblasta - 7 months ago 19
Python Question

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

Answer

You can use

&&

for logical and

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

Comments