Adobe COLDFUSION 9 Manual page 40

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
<cfoutput query = "GetEmployees">
<cfswitch expression = #Department#>
<cfcase value = "Sales">
#FirstName# #LastName# is in <b>Sales</b><br><br>
</cfcase>
<cfcase value = "Accounting">
#FirstName# #LastName# is in <b>Accounting</b><br><br>
</cfcase>
<cfcase value = "Administration">
#FirstName# #LastName# is in <b>Administration</b><br><br>
</cfcase>
<cfdefaultcase>#FirstName# #LastName# is not in Sales,
Accounting, or Administration.<br>
</cfdefaultcase>
</cfswitch>
</cfoutput>
cfloop and cfbreak
The
tag loops through the tag body zero or more times based on a condition specified by the tag attributes.
cfloop
The
tag exits a
cfbreak
cfloop
cfloop
The
tag provides the following types of loops:
cfloop
Loop type
Description
Index
Loops through the body of the tag and increments a counter variable by a specified amount after each loop until
the counter reaches a specified value.
Conditional
Checks a condition and runs the body of the tag if the condition is True.
Query
Loops through the body of the tag once for each row in a query.
List, file, or array
Loops through the body of the tag once for each entry in a list, each line in a file, or each item in an array.
Collection
Loops through the body of the tag once for each key in a ColdFusion structure or item in a COM/DCOM object.
The following example shows a simple index loop:
<cfloop index = "LoopCount" from = 1 to = 5>
The loop index is <cfoutput>#LoopCount#</cfoutput>.<br>
</cfloop>
The following example shows a simple conditional loop. The code does the following:
Sets up a ten-element array with the word "kumquats" in the fourth entry.
1
2
Loops through the array until it encounters an array element containing "kumquats" or it reaches the end of the
array.
Prints the value of the Boolean variable that indicates whether it found the word kumquats and the array index at
3
which it exited the loop.
tag.
Last updated 8/5/2010
35

Advertisement

Table of Contents
loading

Table of Contents