TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
|| (Logical OR) operator is a binary infix operator that evaluates two Boolean expressions, returning true if at least one of the operands evaluates to true, and false only if both operands evaluate to false.
Evaluation Mechanics
Short-Circuit Evaluation and@autoclosure
Swift employs short-circuit evaluation for the || operator to optimize execution and prevent unnecessary computation. This is implemented at the language level by wrapping the right-hand side operand in an @autoclosure. The evaluation strictly follows a left-to-right order:
- The left-hand side is evaluated first.
- If the left-hand side evaluates to
true, the overall expression immediately resolves totrue. Because the right-hand side is an@autoclosure, its execution is deferred and ultimately bypassed. - If the left-hand side evaluates to
false, the right-hand side closure is executed to determine the final Boolean result.
| LHS | RHS | Result | RHS Evaluated? |
|---|---|---|---|
true | true | true | No |
true | false | true | No |
false | true | true | Yes |
false | false | false | Yes |
Operator Characteristics
- Type Requirement: The left-hand operand must evaluate to a
Bool, while the right-hand operand is defined in the standard library as an@autoclosure () throws -> Bool. Swift is strictly typed and does not support implicit truthiness or type coercion (e.g., non-zero integers or non-nil objects cannot be evaluated using||). - Associativity: Left-associative. Chained operations are grouped and evaluated from left to right. An expression like
a || b || cis parsed as(a || b) || c. - Precedence: The
||operator belongs to theLogicalDisjunctionPrecedencegroup. It has a lower precedence than the&&(Logical AND) operator, which belongs to theLogicalConjunctionPrecedencegroup. In mixed expressions without explicit parentheses,&&is evaluated before||.
Master Swift with Deep Grasping Methodology!Learn More





