Swift OR

Swift OR Operator || is used to perform logical OR operation on two boolean operands.

|| symbol is used for Logical OR Operator in Swift.

OR Operator takes two boolean values as operands and returns the logical OR of the two operands.

The syntax of OR Operator with the two boolean operands is

operand1 || operand2

Truth Table

The following truth table provides the output of OR operator for different values of operands.

operand1operand2operand1 && operand2
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse

OR Operation returns true if any of the operands is true, else it returns false.

Example

In the following Swift program, we will take different boolean values for operands and find the result of OR operation on these operands.

main.swift

var a: Bool
var b: Bool
var result: Bool

a = true
b = true
result = a || b
print("\(a) || \(b) = \(result)")

a = true
b = false
result = a || b
print("\(a) || \(b) = \(result)")

a = false
b = true
result = a || b
print("\(a) || \(b) = \(result)")

a = false
b = false
result = a || b
print("\(a) || \(b) = \(result)")

Output

true || true = true
true || false = true
false || true = true
false || false = false

Conclusion

Concluding this Swift Tutorial, we learned what Swift OR Logical Operator is, and the output of OR Operation for different boolean values as operands, with the help of swift program.