Operator Orelse (Short Circuit Inclusive Disjunction)
 
Returns the short circuit-or (Inclusive Disjunction) of two numeric values

Syntax

Declare Operator OrElse ( ByRef lhs As T1, ByRef rhs As T2 ) As Ret

Usage

result = lhs OrElse rhs

Parameters

lhs
The left-hand side expression.
T1
Any numeric type.
rhs
The right-hand side expression.
T2
Any numeric type.
Ret
An Integer.

Return Value

Returns the short circuit-or (inclusive disjunction) of the two operands.

Description

This operator evaluates the left hand side expression. If the result is nonzero, then -1 (true) is immediately returned. If the result is zero then the right hand side is evaluated, and the logical result from that is returned, returning -1 (true) for a nonzero value or 0 (false) for zero.

The truth table below demonstrates all combinations of a short circuit-or operation, the '-' denotes that the operand is not evaluated.

Lhs ValueRhs ValueResult
000
0nonzero-1
nonzero--1


Short-circuiting is performed - only expressions needed to calculate the result are evaluated.

The return type is always an Integer, of the value 0 or -1, denoting false and true respectively.

This operator cannot be overloaded for user-defined types.

Example

' Using the ORELSE operator on two numeric values
Dim As Integer numeric_value1, numeric_value2
numeric_value1 = 15
numeric_value2 = 30

'Result = -1
Print numeric_value1 OrElse numeric_value2
Sleep


Differences from QB

  • This operator was not available in QB.

See also