The And Logical Operator is used to combine two Boolean expressions together. The And operator evaluates to True only if both the left side and the right side are True. If either side is False, or if both sides are False, the result is False.
The short syntax structure uses the && symbol:
VALUE && VALUEThe long syntax structure uses the word AND:
VALUE AND VALUEThe And operator follows this logic:
PRINTLN TRUE && TRUE // Displays "TRUE"
PRINTLN TRUE && FALSE // Displays "FALSE"
PRINTLN FALSE && TRUE // Displays "FALSE"
PRINTLN FALSE && FALSE // Displays "FALSE"NEW BOOL result1 = TRUE && TRUE
NEW BOOL result2 = TRUE && FALSE
NEW BOOL result3 = FALSE && FALSE
PRINTLN result1 // Displays "TRUE"
PRINTLN result2 // Displays "FALSE"
PRINTLN result3 // Displays "FALSE"NEW BOOL hasTicket = TRUE
NEW BOOL hasID = TRUE
NEW BOOL canEnter = hasTicket && hasID
PRINTLN canEnter // Displays "TRUE"NEW BOOL isStudent = TRUE
NEW BOOL hasDiscount = FALSE
NEW BOOL getsDiscount = isStudent && hasDiscount
PRINTLN getsDiscount // Displays "FALSE"The And operator is commonly used to combine multiple Comparison Operators.
NEW INT age = 25
NEW BOOL inRange = ( age >= 18 ) && ( age <= 65 )
PRINTLN inRange // Displays "TRUE"NEW INT score = 85
NEW INT attendance = 95
NEW BOOL passed = ( score >= 60 ) && ( attendance >= 80 )
PRINTLN passed // Displays "TRUE"NEW FLOAT temperature = 72.5
NEW FLOAT humidity = 45.0
NEW BOOL isComfortable = ( temperature >= 68.0 ) && ( temperature <= 78.0 ) && ( humidity <= 60.0 )
PRINTLN isComfortable // Displays "TRUE"The And operator is frequently used in If statements to check multiple conditions.
NEW INT age = 21
NEW BOOL hasID = TRUE
IF ( age >= 18 ) && hasID
PRINTLN "Access granted"
ELSE
PRINTLN "Access denied"
END IF
// Displays "Access granted"NEW INT credits = 120
NEW FLOAT gpa = 3.5
IF ( credits >= 120 ) && ( gpa >= 2.0 )
PRINTLN "Eligible for graduation"
ELSE
PRINTLN "Requirements not met"
END IF
// Displays "Eligible for graduation"NEW STR username = "admin"
NEW STR password = "secure123"
NEW BOOL isLoggedIn = FALSE
IF ( username == "admin" ) && ( password == "secure123" )
SET isLoggedIn = TRUE
PRINTLN "Login successful"
ELSE
PRINTLN "Invalid credentials"
END IF
// Displays "Login successful"The And operator can control loop continuation by requiring multiple conditions to be True.
NEW INT counter = 1
NEW BOOL keepGoing = TRUE
WHILE ( counter <= 5 ) && keepGoing
PRINTLN "Iteration: " .. counter
SET counter = counter + 1
IF counter == 4
SET keepGoing = FALSE
END IF
END WHILE
// Displays: Iteration: 1, Iteration: 2, Iteration: 3NEW INT i = 1
NEW BOOL hasError = FALSE
WHILE ( i <= 10 ) && ( hasError == FALSE )
PRINTLN "Processing item " .. i
SET i = i + 1
IF i == 6
SET hasError = TRUE
END IF
END WHILE
PRINTLN "Loop ended"You can chain multiple And operators to require all conditions to be True.
NEW BOOL condition1 = TRUE
NEW BOOL condition2 = TRUE
NEW BOOL condition3 = TRUE
NEW BOOL allTrue = condition1 && condition2 && condition3
PRINTLN allTrue // Displays "TRUE"NEW INT age = 25
NEW BOOL hasLicense = TRUE
NEW BOOL hasInsurance = TRUE
NEW BOOL canDrive = ( age >= 16 ) && hasLicense && hasInsurance
PRINTLN canDrive // Displays "TRUE"NEW INT score1 = 85
NEW INT score2 = 90
NEW INT score3 = 78
NEW BOOL allPassing = ( score1 >= 60 ) && ( score2 >= 60 ) && ( score3 >= 60 )
PRINTLN allPassing // Displays "TRUE"NEW INT day = 15
NEW INT month = 6
NEW INT year = 2026
NEW BOOL isValidDate = ( day >= 1 ) && ( day <= 31 ) && ( month >= 1 ) && ( month <= 12 ) && ( year > 0 )
IF isValidDate == TRUE
PRINTLN "Valid date"
ELSE
PRINTLN "Invalid date"
END IF
// Displays "Valid date"NEW INT passwordLength = 12
NEW BOOL hasUppercase = TRUE
NEW BOOL hasNumber = TRUE
NEW BOOL isStrong = ( passwordLength >= 8 ) && hasUppercase && hasNumber
IF isStrong == TRUE
PRINTLN "Password is strong"
ELSE
PRINTLN "Password is weak"
END IF
// Displays "Password is strong"NEW BOOL isMember = TRUE
NEW FLOAT purchaseAmount = 150.0
NEW BOOL hasCode = TRUE
NEW BOOL getsDiscount = isMember && ( purchaseAmount >= 100.0 ) && hasCode
IF getsDiscount == TRUE
PRINTLN "Discount applied!"
ELSE
PRINTLN "No discount available"
END IF
// Displays "Discount applied!"NEW BOOL hasKey = TRUE
NEW BOOL hasMap = TRUE
NEW BOOL reachedExit = TRUE
NEW BOOL wins = hasKey && hasMap && reachedExit
IF wins == TRUE
PRINTLN "You win!"
ELSE
PRINTLN "Keep playing"
END IF
// Displays "You win!"The And operator requires all conditions to be True, while the Or operator only requires at least one condition to be True.
NEW BOOL a = TRUE
NEW BOOL b = FALSE
PRINTLN a && b // Displays "FALSE" (both must be TRUE)
PRINTLN a || b // Displays "TRUE" (at least one is TRUE)NEW BOOL hasTicket = TRUE
NEW BOOL hasInvite = FALSE
NEW BOOL canEnterWithAnd = hasTicket && hasInvite
NEW BOOL canEnterWithOr = hasTicket || hasInvite
PRINTLN canEnterWithAnd // Displays "FALSE"
PRINTLN canEnterWithOr // Displays "TRUE"You can combine And and Or operators to create complex logical expressions. Use parentheses to control the order of evaluation.
NEW BOOL isStudent = TRUE
NEW BOOL isSenior = FALSE
NEW BOOL hasCoupon = TRUE
NEW BOOL getsDiscount = ( isStudent || isSenior ) && hasCoupon
PRINTLN getsDiscount // Displays "TRUE"NEW INT age = 25
NEW BOOL isVIP = FALSE
NEW BOOL hasMembership = TRUE
NEW BOOL hasAccess = ( age >= 18 ) && ( isVIP || hasMembership )
PRINTLN hasAccess // Displays "TRUE"When using And, if the left side is False, the result is always False regardless of the right side. This is called short-circuit evaluation.
NEW BOOL checkFirst = FALSE
NEW BOOL checkSecond = TRUE
NEW BOOL result = checkFirst && checkSecond
PRINTLN result // Displays "FALSE" (first condition failed, second doesn't matter)NEW INT value = 50
NEW INT min = 1
NEW INT max = 100
NEW BOOL inBounds = ( value >= min ) && ( value <= max )
PRINTLN inBounds // Displays "TRUE"NEW BOOL task1 = TRUE
NEW BOOL task2 = TRUE
NEW BOOL task3 = TRUE
NEW BOOL allComplete = task1 && task2 && task3
IF allComplete == TRUE
PRINTLN "All tasks complete!"
ELSE
PRINTLN "Some tasks remaining"
END IF
// Displays "All tasks complete!"NEW BOOL engineOn = TRUE
NEW INT fuelLevel = 50
NEW INT oilPressure = 30
NEW BOOL safeToOperate = engineOn && ( fuelLevel > 10 ) && ( oilPressure > 20 )
IF safeToOperate == TRUE
PRINTLN "Safe to operate"
ELSE
PRINTLN "Safety check failed"
END IF
// Displays "Safe to operate"NEW INT x = 5
NEW INT y = 10
PRINTLN x && y // Type error! And requires Boolean valuesNEW INT age = 25
// Wrong: Missing comparison
// IF age && hasID // Syntax error!
// Correct: Use comparison operators
NEW BOOL hasID = TRUE
IF ( age >= 18 ) && hasID
PRINTLN "Valid"
END IFNEW BOOL hasTicket = TRUE
NEW BOOL hasInvite = FALSE
// And requires both (wrong if you only need one)
IF hasTicket && hasInvite
PRINTLN "Can enter"
END IF
// Or requires at least one (correct for this scenario)
IF hasTicket || hasInvite
PRINTLN "Can enter"
END IF
// Displays "Can enter"NEW BOOL a = TRUE
NEW BOOL b = FALSE
NEW BOOL c = TRUE
// Ambiguous without parentheses
NEW BOOL result1 = a || b && c
// Clear with parentheses
NEW BOOL result2 = a || ( b && c )
NEW BOOL result3 = ( a || b ) && c
PRINTLN result2 // Displays "TRUE"
PRINTLN result3 // Displays "TRUE"