SunQuest
 
       ColdFusion
  Home arrow ColdFusion arrow What You Must Know About Operators in Cold...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
COLDFUSION

What You Must Know About Operators in ColdFusion!
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 6
    2005-08-22

    Table of Contents:
  • What You Must Know About Operators in ColdFusion!
  • Conditional Operators
  • Logical Operators
  • String Operator

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    What You Must Know About Operators in ColdFusion!


    (Page 1 of 4 )

    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.

    ColdFusion like other programming languages has many operators of the following basic types:

    • Arithmetic Operators
    • Conditional Operators
    • Logical Operators
    • String Operator
    Arithmetic Operators

    When dealing with numbers it is essential to understand how the operators function. Different programming languages use the symbols in slightly different ways. For example the unary operators in ColdFusion do not work the same way as the unary operators in JavaScript. ColdFusion arithmetic operators are mostly binary. Generally, two operands, operand 1 and operand 2 are operated upon by placing the operator in between them, [Operand 1][operator][operand 2] and the resulting value depends on the type of operator.

    Operators Description Examples & Comments
    +, -, *, / Basic add, subtract, multiply and divide (the right hand operand cannot be zero)
    • Add: #x# + #y#
    • Subtract: #x# - #y#
    • Multiply: #x# * #y#(x*y = y*x)
    • Divide: #x# / #y#
    +, - Used just to change the sign of variable. i.e, to change 5 to -5
    • -#x# ( to get a negative of x).
    • <Operator><Operand>
    MOD Remainder left after a division
    • Example: 5 mod 2 is 1
    • Sign of modulus is sign of dividend
    • The right operand cannot be zero
    ^ : the Caret Exponentiation (raising the power)
    • Example: #x# ^ 2(exponent is 2)
    • The exponent can be floating point, negative
     Represents integer division
    • Example: #x# #z#
    • For floating point numbers the integer part is used.
    Examples using arithmetic operators

    The following example shows several of the operators and their usage.

    <!--- Arithmetic Operators --->
    <!---Arith.cfm                   --->
    <!--- Author: Jay Krishnaswamy --->
    <cfscript>
    WriteOutput("<b>Arithmetic Operations</b><br/>");
    apples=5;
    writeoutput("There are " & #apples# & " Apples <br/>");
    oranges=10;
    writeoutput("There are " & #oranges# & " Oranges<br/>");
    bananas=0;
    writeoutput("There are " & #bananas# & " bananas<br/><hr width='40%'' 
    align=left>"); //Inside <cfscript/> use double slash for comments //Addition WriteOutput("Total of apples and bananas = " & #apples#+#bananas# ); WriteOutput("<br/>"); WriteOutput("How many more oranges than apples?: " & # oranges#-#apples#); WriteOutput("<br/>"); WriteOutput("3 times the number of apples are " & 3*#apples# & " apples"); WriteOutput("<br/>"); WriteOutput("Half the number of oranges are " & #oranges# /2 & " oranges"); WriteOutput("<br/>"); WriteOutput("5 divided by 0 is:" ); WriteOutput( 5/0 & "<br/>"); </cfscript>

    <cfset .../> tags and <cfoutput> ..... </cfoutput> tags can also be used, but you may have to write a lot of such tags for the example shown.

    Browsing arith.cfm

    The following picture shows the display when browsed with FireFox. It appears that FireFox can display the resulting html up to the line which has the error, but IE 6.0 just gives an HTTP 500 error. For displaying in IE 6.0, the last line needs to be modified.

    More ColdFusion Articles
    More By Jayaram Krishnaswamy


       · Sitting at an undetermined distance from the readers, the single, most important...
     

    COLDFUSION ARTICLES

    - 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...
    - My First Application on ColdFusion MX Server







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway