Swift AND

Swift AND Operator && is used to perform logical AND operation on two boolean operands.

&& symbol is used for Logical AND Operator in Swift.

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

The syntax of AND Operator with the two boolean operands is

operand1 && operand2

Truth Table

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

operand1operand2operand1 && operand2
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse

AND Operation returns true only if both the operands are true, else it returns false.

ADVERTISEMENT

Example

In the following Swift program, we will take different boolean values for operands and find the result of AND 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 = false
false && true = false
false && false = false

Conclusion

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