Home »
Swift »
Swift Programs
Swift program to demonstrate the logical OR (||) operator
Here, we are going to demonstrate the logical OR (||) operator in Swift programming language.
Last Updated : May 31, 2021
Swift - Logical OR (||) operator
Here, we will compare variables using the logical OR (||) operator and print the appropriate message on the console screen.
In the case of logical OR operation, if any one condition is true then the result will be true otherwise result is considered false.
Swift program to demonstrate the logical OR (||) operator
The source code to demonstrate the logical OR (||) operator is given below. The given program is compiled and executed successfully.
// Swift program to demonstrate the
// logical OR (||) operator
import Swift;
var num1=10;
var num2=50;
var num3=10;
if(num1==num2 || num1==num3)
{
print("Hello");
}
else
{
print("Hii");
}
Output
Hello
...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 three variables num1, num2, num3 that are initialized with 10, 50, 10 respectively. Then we compared variables and performed a logical OR (||) operation to compare numbers and printed the appropriate message on the console screen.
Swift Basic Programs »
Advertisement
Advertisement