User Guide

Table Of Contents
Using CFScript statements 129
Using conditional processing statements
CFScript includes the following conditional processing statements:
if and else statements, which serve the same purpose as the cfif, cfelseif, and cfelse
tags
switch, case, and default statements, which are the equivalents of the cfswitch, cfcase,
and
cfdefaultcase tags
Using if and else statements
The
if and else statements have the following syntax:
if(expr) statement [else statement]
In its simplest form, an if statement looks like this:
if(value EQ 2700)
message = "You’ve reached the maximum";
A simple if-else statement looks like the following:
if(score GT 1)
result = "positive";
else
result = "negative";
CFScript does not include an elseif statement. However, you can use an if statement
immediately after an
else statement to create the equivalent of a cfelseif tag, as the following
example shows:
if(score GT 1)
result = "positive";
else if(score EQ 0)
result = "zero";
else
result = "negative";
As with all conditional processing statements, you can use curly braces to enclose multiple
statements for each condition, as follows:
if(score GT 1) {
result = "positive";
message = "The result was positive.";
}
else {
result = "negative";
message = "The result was negative.";
}
Note: Often, you can make your code clearer by using braces even where they are not required.