#### Revision [17764]

This is an old revision of KeyPgOpAndAlso made by FxMwikki on 2015-09-12 04:46:05.

### Operator ANDALSO (Short Circuit Conjunction)

Returns the short circuit-and (conjunction) of two numeric values

**Syntax:**

KeyPgDeclare declare KeyPgOperator operator

**AndAlso**( KeyPgByref byref*lhs*KeyPgAs as*T1*, KeyPgByref byref*rhs*KeyPgAs as*T2*) KeyPgAs as*Ret***Usage:**

`
`

*result*=

*lhs*

**AndAlso**

*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

`and`*T1*`).`*T2***Return Value:**

Returns the short circuit-and (conjunction) of the two operands.

**Description:**

This operator evaluates the left hand side expression. If the result is zero, then zero is immediately returned. If the result is nonzero then the right hand side is evaluated, and the logical result from that is returned.

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

Lhs Value | Rhs Value | Result |

0 | - | 0 |

nonzero | 0 | 0 |

nonzero | nonzero | -1 |

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

The return type is always an

The return type is always an

`KeyPgInteger Integer`, of the value`0`or`-1`, denoting false and true respectively.
This operator cannot be overloaded for user-defined types.

**Examples:**

'' Using the ANDALSO operator to guard against array access

'' when the index is out of range

Dim As Integer isprime(1 To 10) = { _

_ ' 1 2 3 4 5 6 7 8 9 10

0, 1, 1, 0, 1, 0, 1, 0, 0, 0 _

}

Dim As Integer n

Input "Enter a number between 1 and 10: ", n

'' isprime() array will only be accessed if n is in range

If (n >= 1 And n <= 10) andalso isprime(n) Then

Print "n is prime"

Else

Print "n is not prime, or out of range"

End If

'' when the index is out of range

Dim As Integer isprime(1 To 10) = { _

_ ' 1 2 3 4 5 6 7 8 9 10

0, 1, 1, 0, 1, 0, 1, 0, 0, 0 _

}

Dim As Integer n

Input "Enter a number between 1 and 10: ", n

'' isprime() array will only be accessed if n is in range

If (n >= 1 And n <= 10) andalso isprime(n) Then

Print "n is prime"

Else

Print "n is not prime, or out of range"

End If

**Differences from QB:**

- This operator was not available in QB.

**See also:**

Back to Short Circuit Operators

Back to Operators