What You Must Know About Operators in ColdFusion! - Conditional Operators
(Page 2 of 4 )
The next table shows the details of the conditional operators available and their usage. The evaluated value of the operation is Boolean (true or false). If the condition is satisfied, the expression yields a True, otherwise it yields a false. Again, although true means 'Yes', as well as any non-zero number, make sure the version supports it. For example 'Yes' and 'No' are not supported in MX 6.1. This is the reason they have been defined in the example shown, conditional.cfm.
Notice that the output to the screen contains both the text portion as well as the evaluated value. However WriteOutput(#x# IS #y#); should print to screen, the evaluated value of the conditional expression. Again, unlike JavaScript, the greater than and less than are using the literal values, instead of > and <.
All of these operators produce a Boolean outcome: NO, or YES.
| Operator | Description | Example & Comments |
|---|
| IS | Case-insensitive comparison of the two values; returns true if the values are identical. | All of these mean the same thing - #x# IS #y#
- #x# EQUAL #y#
- #x# EQ #y#
|
| IS NOT | Behavior opposite to that of IS | All of these mean the same thing - #x# IS NOT #y#
- #x# NOT EQUAL #y#
- #x# NEQ #y#
|
| CONTAINS | Checks to see if the value on the left is contained in the value on the right; returns true if it is. | #x# CONTAINS #y# Pertinent to strings Example: "Welcome" contains "come" |
| Does Not Contain | Behavior opposite to that of Contains | #x# DOES NOT CONTAIN #y# Pertinent to strings |
| GREATER THAN | Checks to see if the value on the left is greater than the value on the right; returns true if it is. | Both of these mean the same thing - #x# GREATER THAN #y#
- #x# GT #y#
can be used with both text and numbers |
| LESS THAN | Behavior opposite to that of Greater than | Both of these mean the same thing - #x# LESS THAN #y#
- #x# LT #y#
can be used with both text and numbers |
| GREATER THAN OR EQUAL TO | Checks to see if the value on the left is greater than or equal to the value on the right; returns true if it is. | All of these mean the same thing - #x# GREATER THAN OR EQUAL TO #y#
- #x# GTE #y#
- #x# GE #y#
|
| LESS THAN OR EQUAL TO | Checks to see if the value on the left is less than or equal to the value on the right; returns true if it is. | All of these mean the same thing- #x# LESS THAN OR EQUAL TO #y#
- #x# LTE #y#
- #x# LE #y#
|
Example using operatorsThe following example assumes a number of variables, of simple types, string and number, and evaluates the outcome of performing conditional operations using the CF MAX conditional operators. The output is written to screen. The output contains the text part of the argument as well as the Boolean part of the argument. Hence the function evaluate was used. The next screen shot shows the code in Sapien's color coded screen. Color coding helps a lot in weeding out the code.

The output of this code shows the evaluated values, in the next picture.
Next: Logical Operators >>
More ColdFusion Articles
More By Jayaram Krishnaswamy