Home arrow ColdFusion arrow Page 2 - What You Must Know About Operators in ColdFusion!
COLDFUSION

What You Must Know About Operators in ColdFusion!


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.

Author Info:
By: Jayaram Krishnaswamy
Rating: 4 stars4 stars4 stars4 stars4 stars / 21
August 22, 2005
TABLE OF CONTENTS:
  1. · What You Must Know About Operators in ColdFusion!
  2. · Conditional Operators
  3. · Logical Operators
  4. · String Operator

print this article
SEARCH DEVARTICLES

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 operators

The 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.

 


blog comments powered by Disqus
COLDFUSION ARTICLES

- Adobe ColdFusion Just Got More RAD
- How to Access a SQL Anywhere Database with C...
- CFXML: Probing XMLDOM in ColdFusion
- Creating a Web Service with ColdFusion: the ...
- CFAjax: What it is and How to Use it
- Querying SQL 2000 Server from ColdFusion
- Introduction to ColdFusion Markup Language, ...
- Introduction to ColdFusion Markup Language
- Databases and Dreamweaver MX 2004, concluded
- Databases and Dreamweaver MX 2004
- Welcome to Coldfusion MX 6.1, concluded
- Welcome to Coldfusion MX 6.1
- What You Must Know About ColdFusion Flow-Con...
- What You Must Know About Operators in ColdFu...
- Everything You Must Know About ColdFusion Va...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials