Home »
Swift »
Swift Programs
Swift program to demonstrate the logical NOT (!) operator
Here, we are going to demonstrate the logical NOT (!) operator in Swift programming language.
Last Updated : May 31, 2021
Swift - Logical NOT (!) operator
Here, we will demonstrate the logical NOT (!) operator and print the appropriate message on the console screen.
The logical NOT operation reverse the condition result. If the result of the condition is true then it becomes false or vice versa.
Swift program to demonstrate the logical NOT (!) operator
The source code to demonstrate the logical NOT (!) operator is given below. The given program is compiled and executed successfully.
// Swift program to demonstrate the
// logical NOT (!) operator
import Swift;
var num1=10;
var num2=10;
if !(num1==num2)
{
print("Hello");
}
else
{
print("Hii");
}
Output
Hii
...Program finished with exit code 0
Press ENTER to exit console.
Explanation
In the above program, we imported a package Swift to use the print() function using the below statement,
import Swift;
Here, we created two variables num1, num2 that are initialized with 10, 10 respectively. Then we compared variables and performed a logical NOT (!) operation and printed the appropriate message on the console screen.
Swift Basic Programs »
Advertisement
Advertisement