Swift If Statement with OR Operator

To combine two conditions in If statement with OR logical operator, use || between the conditions.

The syntax to use OR logical operator with If statement is

if ( condition_1 || condition_2 ) {


In the following program, we will check if the number is greater than 5, or if the number is even, using an if statement. We shall combine the conditions using OR logical operator.


var n = 9

if ( (n > 5) || (n % 2 == 0) ) {
    print("Atleast one of the conditions is true.")
} else {
    print("Both the conditions are false.")


Swift If Statement with OR Operator


In this Swift Tutorial, we learned how to combine two conditions with OR logical operator in the if boolean expression.