user3185748
user3185748

Reputation: 2538

Multiple Conditions for Swift 'If' Statement?

Is there a way to write an If statement is Swift such as the following?

if a>b or c/d {
    //Do Something
}

Upvotes: 23

Views: 67682

Answers (3)

M Mahmud Hasan
M Mahmud Hasan

Reputation: 1173

for and operation we can use

if x==y && y == z { //perform some operations }

for or operation we can use

if x==y || y == z { //perform some operations }

Upvotes: 3

dersvenhesse
dersvenhesse

Reputation: 6414

Just like everywhere:

if a > b || d % c == 0 {
   // do sth
}

I assume your c/d means you'd like d to be a multiple of c.

Upvotes: 18

Sulthan
Sulthan

Reputation: 130102

Swift uses the same operators as all C-based languages, so

if a > b || c < d {
}

where || is the OR operator, && is the AND operator.

The list of all operators can be found in Swift Basic Operators

Not sure what c/d condition is supposed to mean.

Upvotes: 12

Related Questions