AND
Logical conjunction operator. Returns TRUE only if both operands are TRUE.
Syntax
expression1 AND expression2
expression1 && expression2
Truth Table
| A | B | A AND B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| FALSE | FALSE | FALSE |
Examples
Example file:
-- AND keyword examples
-- Basic AND Operations
#EVAL TRUE AND TRUE
#EVAL TRUE AND FALSE
#EVAL FALSE AND TRUE
#EVAL FALSE AND FALSE
-- Symbolic Alternative (&&)
#EVAL TRUE && TRUE
#EVAL TRUE && FALSE
-- In Conditional Logic
ASSUME age IS A NUMBER
ASSUME hasLicense IS A BOOLEAN
DECIDE canDrive IS age >= 16 AND hasLicense
#CHECK canDrive
-- Chaining Multiple Conditions
GIVEN a IS A BOOLEAN
b IS A BOOLEAN
c IS A BOOLEAN
allTrue a b c MEANS a AND b AND c
#EVAL allTrue TRUE TRUE TRUE
#EVAL allTrue TRUE TRUE FALSE
-- Layout-Sensitive AND (Vertical Format)
ASSUME personAge IS A NUMBER
ASSUME personIncome IS A NUMBER
ASSUME hasCriminalRecord IS A BOOLEAN
DECIDE isEligible IS
personAge >= 18
AND personIncome > 30000
AND NOT hasCriminalRecord
#CHECK isEligible
-- Complex Expressions with AND
GIVEN x IS A NUMBER, y IS A NUMBER
inRange x y MEANS x >= 0 AND x <= 100 AND y >= 0 AND y <= 100
#EVAL inRange 50 50
#EVAL inRange 150 50
-- AND with Comparisons
GIVEN score IS A NUMBER
passingGrade score MEANS score >= 60 AND score <= 100
#EVAL passingGrade 75
#EVAL passingGrade 55
-- AND in IF Expressions
GIVEN userAge IS A NUMBER, hasPermission IS A BOOLEAN
accessLevel userAge hasPermission MEANS
IF userAge >= 18 AND hasPermission
THEN "full access"
ELSE "restricted"
#EVAL accessLevel 25 TRUE
#EVAL accessLevel 25 FALSE
Basic Usage
#EVAL TRUE AND TRUE -- TRUE
#EVAL TRUE AND FALSE -- FALSE
#EVAL FALSE AND TRUE -- FALSE
#EVAL FALSE AND FALSE -- FALSE
In Conditions
GIVEN age IS A NUMBER
GIVEN hasLicense IS A BOOLEAN
DECIDE canDrive IS age >= 16 AND hasLicense
Symbolic Alternative
DECIDE result IS TRUE && FALSE
Chaining Multiple Conditions
GIVEN a IS A BOOLEAN
GIVEN b IS A BOOLEAN
GIVEN c IS A BOOLEAN
allTrue a b c MEANS a AND b AND c
Layout-Sensitive AND
L4 supports vertical AND with indentation:
DECIDE eligible IS
age >= 18
AND income > 30000
AND NOT hasCriminalRecord
Asyndetic AND
Implicit operators using punctuation.
Ellipsis (...) - Implicit AND
Example:
-- Example: Asyndetic operators (... and ..)
-- Implicit AND and OR using punctuation
citizen MEANS TRUE
over18 MEANS TRUE
hasID MEANS TRUE
approved MEANS TRUE
pending MEANS FALSE
review MEANS FALSE
-- Ellipsis (...) = implicit AND
eligible1 MEANS citizen ... over18 ... hasID
-- Equivalent to: (citizen AND over18 AND hasID)
-- Double dot (..) = implicit OR
inProgress MEANS approved .. pending .. review
-- Equivalent to: (approved OR pending OR review)
#EVAL eligible1
#EVAL inProgress
Short-Circuit Evaluation
AND evaluates lazily - if the first operand is FALSE, the second is not evaluated.
Related Keywords
See Also
- Logical Operators - All logical operators