Operator

Or


Description

Used to perform a logical Or comparison between two Boolean expressions Or a bitwise Or comparison between two integers.

Usage

result = expression1 Or expression2

Part

Type

Description

result

Boolean or Integer

A Boolean value if expression1 and expression2 are boolean and an integer if expression1 and expression2 are integers.

expression1

Boolean or Integer

Any valid Boolean or integer expression. Expression1 and expression2 must be of the same data type.

expression2

Boolean or Integer

Any valid Boolean or integer expression. Expression1 and expression2 must be of the same data type.

Notes

The Or operator is overloaded. If it is passed two booleans, it performs a logical Or and returns a boolean. If it is passed two integers, it performs a bitwise Or operation on the integers and returns an integer. In this case, it is equivalent to calling the BitOr method of the Bitwise class.

In the first instance, if either boolean expression evaluates to True, then result is True. If both expressions evaluate to False then result is False. The truth table for logical operators is shown below.

Expression1

Expression2

Or

And

Xor

True

True

True

True

False

True

False

True

False

True

False

True

True

False

True

False

False

False

False

False

If you pass two integers, Or returns an integer that is the result of comparing each bit of the two integers passed and assigning 1 to the bit position in the integer returned if either of the bits in the same position in the integers passed are 1. Otherwise, 0 is assigned to the bit position.

The following table shows the results for bitwise operators:

Integer1

Integer2

Or

And

Xor

0

0

0

0

0

0

1

1

0

1

1

0

1

0

1

1

1

1

1

0

Sample code

This example uses the Or operator to perform logical comparisons

Var a As Boolean
Var b As Boolean
Var c As Boolean
Var d As Boolean
a = True
b = False
d = a Or b ' d = True
d = b Or c ' d = False

Using Or with Integer values:

Var i1 As Integer = 4
Var i2 As Integer = 5

Var result As Integer
result = i1 Or i2 ' result = 5

Compatibility

All project types on all supported operating systems.

See also

And, Not, Xor operators; Bitwise class; Operator Or function; Operator precedence