&& Logical operator

Purpose

Logical AND of a true/false status of two or more values

Syntax

i && j

i, j:arguments

Description

If you want to test whether two or more conditions are true, you can use the logical AND operator &&. This function is optimised for performance as it evaluates all conditions from left to right and if it comes across a false condition, any further conditions are not evaluated.

Example

ff("String", 150// Prints True

ff("", 150)        // Prints False

ff("String", 75)   // Prints False

ff("", 75)         // Prints False

 

Function ff(a$, height)

Print Len(a$) && height => 100

(* Prints True only if both conditions are True and/or non-zero *)

EndFunction

Remarks

The logical operator And can be used to perform a similar task but does not have the speed optimization of && and can occasionally produce an odd result.

Local Byte a = 1, b = 2

Print a = 2 && b = // Prints False (quick)

Print a = 2 And b = 2 // Prints 0 (slow)

This logical operator should not be confused with the bitwise AND operator %& which returns erroneous results if used in this way, as can be seen below:

Local Byte a = 1, b = 2

Print a = 1 && b = // Prints True

Print a = 1 And b = 2 // Prints -1

Print a = 1 %& b = // Prints False

See Also

If, ||, ^^, !, Operator Hierarchy

{Created by Sjouke Hamstra; Last updated: 17/09/2014 by James Gaite}