The fabric of a program consists of expressions, large and small, stitched together with operators and interspersed with functions. The larger expressions as well as the functions themselves may be the result of development from a number of smaller expressions. An understanding of the operators and their correct usage is therefore very essential. This tutorial describes the various operators by presenting comprehensive examples of their usage tested on the MX 6.1 server. <CFScript> will be used in all the examples.
What You Must Know About Operators in ColdFusion! - Logical Operators (Page 3 of 4 )
Operator
Truth Table/Description
NOT
Negates the argument. If argument is 'true', it produces 'false', and vice versa
AND
OR
XOR (Exclusive or)
EQV (Equivalence)
IMP (Implication))
Code example
An example with all the operators is shown in the code below, followed by the result of browsing the file. Since the logical operators operate on Boolean operands, it can be seen that the Boolean results obtained by using the conditional operators can be combined using the Boolean operators to evaluate complex conditions (for example, to flag a person based on sex, salary level, and marital status to pick up a certain tax rate range).
logical2.cfm
<cfscript>
YES=TRUE;
NO=FALSE;
WriteOutput("<br><h4>Test Boolean evaluations</h4>");
WriteOutput("<b>-----OR-----</b><br/>");
WriteOutput("[TRUE] <b>OR</b> [FALSE] is : " & Evaluate(True OR False));
WriteOutput("<p></p>");
WriteOutput("<br><b>-----AND-----</b><br/>");
WriteOutput("[TRUE] <b>AND</b> [FALSE] is : " & Evaluate(True AND False));
WriteOutput("<p></p>");
WriteOutput("<br><b>-----XOR-----</b><br/>");
WriteOutput("[TRUE] <b>XOR</b> [FALSE] is : " & Evaluate(True XOR False));
WriteOutput("<p></p>");
WriteOutput("<br><b>-----EQV-----</b><br/>");
WriteOutput("[TRUE] <b>EQV</b> [FALSE] is : " & Evaluate(True EQV False));
WriteOutput("<p></p>");WriteOutput("<br><b>-----IMP-----</b><br/>");
WriteOutput("[TRUE] <b>IMP</b> [FALSE] is : " & Evaluate(True IMP False));
</cfscript>