MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 111

Developing coldfusion mx applications
Table of Contents

Advertisement

<cfloop index="loopcount" from=1 to=12>
<cfoutput>
#months[loopcount]#<br>
</cfoutput>
</cfloop>
Using nested loops for 2D and 3D arrays
To output values from 2D and 3D arrays, you must employ nested loops to return array data.
With a one-dimensional (1D) array, a single
example. With arrays of dimension greater than one, you need to maintain separate loop counters
for each array level.
Nesting cfloop tags for a 2D array
The following example shows how to handle nested
It also uses nested
cfloop
<cfset my2darray=arraynew(2)>
<cfloop index="loopcount" from=1 to=12>
<cfloop index="loopcount2" from=1 to=2>
<cfset my2darray[loopcount][loopcount2]=(loopcount * loopcount2)>
</cfloop>
</cfloop>
<p>The values in my2darray are currently:</p>
<cfloop index="OuterCounter" from="1" to="#ArrayLen(my2darray)#">
<cfloop index="InnerCounter" from="1"
to="#ArrayLen(my2darray[OuterCounter])#">
<cfoutput>
<b>[#OuterCounter#][#InnerCounter#]</b>:
#my2darray[OuterCounter][InnerCounter]#<br>
</cfoutput>
</cfloop>
</cfloop>
Nesting cfloop tags for a 3D array
For 3D arrays, you simply nest an additional
values first to keep the code short.)
<cfloop index="Dim1" from="1" to="#ArrayLen(my3darray)#">
<cfloop index="Dim2" from="1" to="#ArrayLen(my3darray[Dim1])#">
<cfloop index="Dim3" from="1"
to="#ArrayLen(my3darray[Dim1][Dim2])#">
<cfoutput>
<b>[#Dim1#][#Dim2#][#Dim3#]</b>:
#my3darray[Dim1][Dim2][Dim3]#<br>
</cfoutput>
</cfloop>
</cfloop>
</cfloop>
cfloop
tags to populate the array:
cfloop
is sufficient to output data, as in the previous
tags to output data from a 2D array.
cfloop
tag. (This example does not set the array
Populating arrays with data
111

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents