Multiple Conditions for Swift 'If' Statement?

后端 未结 2 1503
一向
一向 2021-02-05 09:19

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

if a>b or c/d {
    //Do Something
}
相关标签:
2条回答
  • 2021-02-05 10:02

    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.

    0 讨论(0)
  • 2021-02-05 10:03

    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.

    0 讨论(0)
提交回复
热议问题