# Logical or operator (||)

**||**Value2

## Value1 — Logical or { Logical }

The first value to compare.

## Value2 — Logical or { Logical }

The second value to compare.

## Returns — Logical or { Logical }

TRUE if one or both values are TRUE and FALSE otherwise.

Returns TRUE if one or both values are TRUE and FALSE otherwise. (Field1 = 3) || (Field2 <
10)(Field1 = 3) || (Field2
<
10) returns TRUE if Field1.ValueField1,Value is equal to 3
**or** Field2.ValueField2,Value is less than 10,
otherwise FALSE is returned.

Use `||`

, && and ! in conjunction with IF to express logical
conditions.

This formula returns 2 only if Field1.ValueField1,Value is 3
**or** Field2.ValueField2,Value is less than 10,
and 4 otherwise:

The formula can also be written using the OR function:

`||`

is written between the values to test, instead of before
them, which can make formulas easier to read.

## || and arrays

`||`

behaves differently from OR when used with arrays. OR always returns a
single TRUE or FALSE value when applied to arrays, but `||`

instead returns an array.

This formula returns TRUE, because at least one array element is TRUE:

This formula, on the other hand, returns the array { FALSE, TRUE, TRUE }{ FALSE; TRUE; TRUE }:

The formula above is equivalent to this formula:

In other words, `||`

returns an array with the same size as the
two arrays given to it. `||`

then compares the values of the two
arrays that are at the same positions and puts TRUE at that position in the
result array if one or both values are TRUE.

`||`

is specific to Calcapp. Spreadsheet users typically use the
+
operator instead to get the array behavior offered by `||`

.
Calcapp also supports the `+`

operator for use with arrays.

## || and FILTER

The array behavior of `||`

is useful when used with functions like
FILTER. One
version of FILTER takes an array to be filtered as its first parameter and a
logical array as its second parameter which determines what elements of the
first array are included in the result array.

Consider this formula:

The formula above returns { 1, 3 }{ 1; 3 }, because 1 and 3 of the first array correspond to TRUE in the second array, unlike 2 and 4, which correspond to FALSE in the second array.

`||`

is perfect for creating a logical array to be used as the
second parameter to FILTER. This formula returns an average of
the test scores obtained by students who are either female or reside in
Arkansas (abbreviated "AK"):

The second parameter, ({ "F",
"M", "M", "F" } = "F") || ({ "CA", "CA", "AZ",
"AK" } = "AK")({ "F"; "M"; "M"; "F" } = "F") ||
({ "CA"; "CA"; "AZ"; "AK" } = "AK") applies `||`

to
the two arrays. This is the first parameter and the array it is equivalent
to:

They are equivalent because only the first and last text strings are equal to "F".

This is the second parameter and the array it is equivalent to:

They are equivalent because only the last text string is equal to "AK".

In effect, `||`

is applied to these two arrays:

The result is the array { TRUE, FALSE, FALSE, TRUE }{ TRUE; FALSE; FALSE; TRUE }, because only the elements that appear first and last in the two arrays are such that at least a single one is TRUE.

In effect, the `||`

and = operators work in tandem to return a
logical array which is TRUE in the positions where either the corresponding
value in the first array is "F" or the corresponding value in the second
array is "AK". That, in turn, causes FILTER to only return test scores for
students that are either female or reside in Arkansas. Here, two test scores
match and are returned ({ 90,
82 }{ 90;
82 }. AVERAGE then returns the average of those
two data points, 86.

## Examples

Returns TRUE.

Returns TRUE.

Returns FALSE.

Returns TRUE.

Returns TRUE if Field1.ValueField1,Value is equal to 3 or Field2.ValueField2,Value is less than 10, otherwise FALSE is returned.

Returns TRUE if Field1.ValueField1,Value is equal to 3
**or** Field2.ValueField2,Value is less than
10, otherwise FALSE is returned. OR is equivalent to `||`

when
arrays are not used.

Returns TRUE, because at least one array element is TRUE.

Returns the array { FALSE, TRUE, TRUE }{ FALSE; TRUE; TRUE }, which is equivalent to { FALSE || FALSE, FALSE || TRUE, TRUE || FALSE }{ FALSE || FALSE; FALSE || TRUE; TRUE || FALSE }.

Returns the array { FALSE,
TRUE, TRUE }{ FALSE; TRUE; TRUE },
which is equivalent to { FALSE || FALSE, FALSE || TRUE, TRUE
|| FALSE }{ FALSE || FALSE; FALSE || TRUE; TRUE
|| FALSE }. +, when used with arrays, is
equivalent to `||`

, and is what spreadsheet users are used to.

Returns { 1, 3,
4 }{ 1; 3;
4 }, which is a filtered version of the { 1, 2, 3, 4 }{ 1; 2; 3; 4 } array,
where only elements which are greater than 3 **or** are odd
are kept. Only 1, 3 and 4 qualify, and as a result are the only elements
that are part of the filtered array.

Returns { 1, 3,
4 }{ 1; 3;
4 }, which is a filtered version of the { 1, 2, 3, 4 }{ 1; 2; 3; 4 } array,
where only elements which are greater than 3 **or** are odd
are kept. Only 1, 3 and 4 qualify, and as a result are the only elements
that are part of the filtered array. This example uses a different
version of FILTER, one that uses a formula
fragment to determine which items are kept. This FILTER version is a
Calcapp extension.