Swift program to demonstrate the logical NOT (!) operator

Here, we are going to demonstrate the logical NOT (!) operator in Swift programming language.
Submitted by Nidhi, on May 31, 2021

Problem Solution:

Here, we will demonstrate the logical NOT (!) operator and print the appropriate message on the console screen.

Logical NOT (!) operation:

The logical NOT operation reverse the condition result. If the result of the condition is true then it becomes false or vice versa.

Program/Source Code:

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 »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.