Swift If Statement with NOT Operator

To use logical NOT operator in If statement use the symbol ! before the condition or boolean expression.

The syntax to use NOT logical operator with If statement is

if ( !condition ) {


In the following program, we will check if the number is not less than 5, using logical NOT operator in if boolean expression.


var n = 9

if ( !(n < 5) ) {
    print("n is not less than 5.")
} else {
    print("n is less than 5")


Swift If Statement with NOT Operator


In this Swift Tutorial, we learned how to use logical NOT Operator in If statement’s boolean expression.