Or ( | )

What is it?

The OR operator inspects the logical state of two expression and, if either of them equate to True, also equates to True. Otherwise, the expression returns False. This is known as Logical Disjunction.

In the diagram below, the green shaded area encompasses the entirety of both operands, but nothing outside. In other words, either or both operands will satisfy the statement, but nothing else.

What is the Syntax?

The OR operator’s syntax is as follows:

( HairColour = "Brown" ) | ( HairColour = "Blonde" );

This equates to True if the person’s hair is brown OR if their hair is blonde.

Why might I want to use this?

Any time you want to execute a statement based on the truth of at least one of its pre-conditions, you should use the OR operator.

Building on the example we discussed in the section on AND operators, we want to expand our property search with the inclusion of an OR statement. The original search produced too few results for a meaningful comparison, so now we want to include an additional postcode with the search to spread the net a little wider.

( PropertyType = "House" ) & ( ( PostCode = "X12 3QZ" ) | ( PostCode = "X14 7BF" ) );

Now, in addition to being True for all houses in the first postcode, it will be True for any houses in the second postcode as well.

 

<< Previous: And ( & ) | Next: Not ( ! )  >>