Swift: Logical OR Operator

Logical OR Operator in Swift:

|| is a logical OR operator in Swift that evaluates two operands and returns a Boolean result. When both operands are false, it returns false, and when at least one operand is true, it returns true.

|| stands for OR and is represented by two pipe symbols.

The truth table below shows all of the possible outcomes of an expression that uses ||.

Logical ExpressionResult
true || truetrue
true || falsetrue
false || truetrue
false || falsefalse

Consider the following example:

var morning = true;
var clouds = false;
if clouds || morning {
 print("Go for a Walk!");

We recommend walk if it is morning or clouds, because you will feel good in either scenario! Since morning is true, the condition will result in true, and the message Go for a Walk! will be printed.

Helpful Tools:

Here are some useful tools to help you along your journey!

Setting up an IDE (Integrated Development Environment) can be difficult for beginners. The Online Compiler will enable you to run your code inside your browser without the need to install an IDE. If you need a more detailed explanation of a specific topic, the best place to find answers is in the Official Documentation.

Scroll to Top
%d bloggers like this: