Q:

Swift program to demonstrate the logical NOT (!) operator

belongs to collection: Swift Basic Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 num1num2 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Swift Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Swift program to demonstrate the closed range oper... >>
<< Swift program to demonstrate the logical OR (||) o...