Skip to content

AND Operator

See Also: OR operator, IAND operator, IOR operator, if command, if function, until, while

Purpose

To combine two variables into one expression that is true when both variables are true, and false when either or both variables are false.

Syntax

( {var1} and {var2} )

where {var1} and {var2} may be either expressions, variables, or constants.

What It Does

When two variables are connected within an encompassing expression by and, the encompassing expression evaluates as true when both variables are true.

Example

move (bFriday and b5PM) to bHappyHour
if (bHappyHour=True) send Info_Box "It's 5 PM on Friday, stop working and go to the bar!"

In this example, if the Boolean variable bFriday and the Boolean variable b5PM are both true, the value of bHappyHour will be true. In that case, an Info_Box MessageBox will appear to tell the user to stop work and celebrate Happy Hour.

Multiple ands may be used to link more than two logical expressions into a single expression that evaluates true when all component expressions are true, and false when one or more component expressions are false:

Example

Boolean bHappyHour
move (bFriday and b5PM and bWorkIsDone) to bHappyHour
if (bHappyHour=True) ;
    send Info_Box "It's 5 PM on Friday, stop working and go to the bar!"
else ;
    send Info_Box "It's not time to party yet, keep working!"

In this example, if all three Boolean variables, bFriday, b5PM, and bWorkIsDone are true, the value of bHappyHour will be true. If any one of bFriday, b5PM, and bWorkIsDone is false, then bHappyHour will evaluate to false.

Notes

  • There is no symbolic substitute for the word and.

  • When ands and ors are intermingled in a single expression without grouping parentheses, evaluation proceeds from left to right with each operator connecting the next expression with the result of all previous (left-lying) ones.

    (true and false or true and false)
    

    would evaluate as false, while

    (true or false and true or false)
    

    would evaluate as true.

  • When using variables other than Booleans (e.g., integers), and expressions do not necessarily return a value of 1. They return the second non-zero argument. Thus,

    (5 and 4)
    

    would evaluate as 4, while

    (-2 and 3)
    

    would evaluate as 3.