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

2 Answers

You can use


&&

for logical and


|| 

for logical or


so you can do

if a > 0 && i == j || f < 3 {
    ...
}

see here

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest