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 exampleAn 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>
Result of evaluation:
Next: String Operator >>
More ColdFusion Articles
More By Jayaram Krishnaswamy