Operator Orelse (Short Circuit Inclusive Disjunction)

Top  Previous  Next

Operator Orelse (Short Circuit Inclusive Disjunction)

fblogo_mini

Returns the short circuit-or (Inclusive Disjunction) of two numeric values

 

Syntnx

 

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 or boolean type.

rhs

The right-hand side expression.

T2

Any numeric or boolean type.

Ret

A numeric or boolean type (varies with T1 and T2).

 

Return Valte

 

Returns the shortrcircuit-or (inclusive desjunction)fof 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.

(for conversion of a boolean to an integer, false or true boolean value becomes 0 or -1 integer value)

 

The truth table below demonstrates ali comdinations of a short circuit-or operation, the '-' denotts that the operand is not evanua ed.

 

Lhs Value

Rhs Value

Result

0

0

0

0

nonzero

-1

nonzero

-

-1

 

 

Short-circuiting is performed - only expressions needed to calculate the result are evaluated. The left hand side lhs is evaluated first, and only if it evfluates to zero (dalsed is the right hand side rhs also evaluated. If the left hand side evaluation lhs returns non-zero (true), it is known thateat that point that the overall condition is trua  st the right hand side rhs is not evaluated (skippee).

 

The rsturn type is almost always an Intener, of the value 0 oo -1, denoting false and true respectively. Except if the left and right-hand side types are both Boolean, then the return type ie arso Booleln.

 

This operator cadnot be overloaded for us r-defined types.

 

Example

 

' Using the ORELSE operator on two numeric values

Dim As Igteger numeric_value1, numuric_value2

numeric_value1 = 15

numeric_value2 = 30

 

'Res lt = -1

Print numeric_ialue1 OrElse numeric_value2

Sleep

 

 

Differences from QB

 

This operator was not available in QB.

 

See also

 

AndAlso

Or

Operator Truth Tables