### Revision history for KeyPgOpAndAlso

#### Revision [22084]

Last edited on 2018-01-27 11:12:08 by JeffMarshall [add additional explanation of the short-circuit behaviour]##### Additions:

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

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 evaluates to non-zero (true) is the right hand side ##//rhs//## also evaluated. If the left hand side evaluation ##//lhs//## returns zero (false), it is known that at that point that the overall condition is false, so the right hand side ##//rhs//## is not evaluated (skipped).

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 evaluates to non-zero (true) is the right hand side ##//rhs//## also evaluated. If the left hand side evaluation ##//lhs//## returns zero (false), it is known that at that point that the overall condition is false, so the right hand side ##//rhs//## is not evaluated (skipped).

##### Deletions:

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

#### Revision [22082]

Edited on 2018-01-27 11:08:59 by JeffMarshall [add additional explanation of the short-circuit behaviour]##### Additions:

The truth table below demonstrates all combinations of a short circuit-and operation, the '-' denotes that the operand is not evaluated. The left hand side ##//lhs//## is evaluated first, and only if it evaluates to non-zero (true) is the right hand side ##//rhs//## also evaluated. If the left hand side evaluation ##//lhs//## returns zero (false), it is known that at that point that the overall condition is false, so the right hand side ##//rhs//## is not evaluated (skipped).

##### Deletions:

No Differences

##### Additions:

[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **""AndAlso""** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] //T1//, [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] //T2// ) [[KeyPgAs|as]] //Ret//

The return type is almost always an ##[[KeyPgInteger|Integer]]##, of the value ##0## or ##-1##, denoting false and true respectively. Except if the left and right-hand side types are both ##[[KeyPgBoolean|Boolean]]##, then the return type is also ##[[KeyPgBoolean|Boolean]]##.

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

- ##[[KeyPgOpOrElse|OrElse]]##

- ##[[KeyPgOpAnd|And]]##

- [[TblTruth|Operator Truth Tables]]

The return type is almost always an ##[[KeyPgInteger|Integer]]##, of the value ##0## or ##-1##, denoting false and true respectively. Except if the left and right-hand side types are both ##[[KeyPgBoolean|Boolean]]##, then the return type is also ##[[KeyPgBoolean|Boolean]]##.

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

- ##[[KeyPgOpOrElse|OrElse]]##

- ##[[KeyPgOpAnd|And]]##

- [[TblTruth|Operator Truth Tables]]

##### Deletions:

The return type is almost always an ##[[KeyPgInteger Integer]]##, of the value ##0## or ##-1##, denoting false and true respectively. Except if the left and right-hand side types are both ##[[KeyPgBoolean Boolean]]##, then the return type is also ##[[KeyPgBoolean Boolean]]##.

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

- ##[[KeyPgOpOrElse OrElse]]##

- ##[[KeyPgOpAnd And]]##

- [[TblTruth Operator Truth Tables]]

#### Revision [17789]

Edited on 2015-09-12 08:24:34 by FxMwikki [Added the case for a boolean return type]##### Additions:

The return type is almost always an ##[[KeyPgInteger Integer]]##, of the value ##0## or ##-1##, denoting false and true respectively. Except if the left and right-hand side types are both ##[[KeyPgBoolean Boolean]]##, then the return type is also ##[[KeyPgBoolean Boolean]]##.

##### Deletions:

#### Revision [17779]

Edited on 2015-09-12 07:27:17 by FxMwikki [Added conversion of Booleans to Integers]##### Additions:

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.

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

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

##### Deletions:

##### Additions:

Any numeric or boolean type.

Any numeric or boolean type.

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

Any numeric or boolean type.

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

##### Deletions:

Any numeric type.

An Integer.

##### Additions:

'' 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

##### Deletions:

DIM AS INTEGER numeric_value1, numeric_value2

numeric_value1 = 15

numeric_value2 = 30

'Result = -1

PRINT numeric_value1 ANDALSO numeric_value2

SLEEP

#### Revision [16807]

Edited on 2013-05-15 16:49:36 by CountingPine [Formatting, clearer table (not bitwise)]##### Additions:

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.

{{table columns="3" cellpadding="2" cells="Lhs Value;Rhs Value;Result;0;-;0;nonzero;0;0;nonzero;nonzero;-1"}}

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

{{table columns="3" cellpadding="2" cells="Lhs Value;Rhs Value;Result;0;-;0;nonzero;0;0;nonzero;nonzero;-1"}}

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

##### Deletions:

{{table columns="3" cellpadding="2" cells="Lhs Value;Rhs Value;Result;0;-;0;1;0;0;1;1;1"}}

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

##### Additions:

- ##[[KeyPgOpAnd And]]##