Swift If Statement with AND Operator

To combine two conditions in If statement with AND logical operator, use && between the conditions.

The syntax to use AND 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, and also if the number is even, in the same if statement. We shall combine the conditions using AND logical operator.


var n = 10

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


Swift If Statement with AND Operator


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