User Guide

Table Of Contents
Using CFScript statements 131
The following switch statement takes the value of a name variable:
1.
If the name is John or Robert, it sets both the male variable and the found variable to True.
2.
If the name is Mary, it sets the male variable to False and the found variable to True.
3.
Otherwise, it sets the found variable to False.
switch(name) {
case "John": case "Robert":
male=True;
found=True;
break;
case "Mary":
male=False;
found=True;
break;
default:
found=False;
} //end switch
Using looping statements
CFScript provides a richer selection of looping constructs than those supplied by CFML tags. It
enables you to create efficient looping constructs similar to those in most programming and
scripting languages. CFScript provides the following looping constructs:
For
While
Do-while
For-in
CFScript also includes the
continue and break statements that control loop processing.
The following sections describe these types of loops and their uses.
Using for loops
The for loop has the following format:
for (initial-expression; test-expression; final-expression) statement
The initial-expression and final-expression can be one of the following:
A single assignment expression; for example, x=5 or loop=loop+1
Any ColdFusion expression; for example, SetVariable("a",a+1)
Empty
The test-expression can be one of the following:
Any ColdFusion expression; for example:
A LT 5
index LE x
status EQ "not found" AND index LT end
Empty