ColdFusion 9.0 Resources |
cfloop: looping over a COM collection or structureDescriptionThe cfloopcollection attribute loops over every object within a COM/DCOM collection object, or every element in a structure:
ExampleThis example uses a COM object to output a list of files. In this example, FFunc is a collection of file2 objects. <cfobject class = FileFunctions.files name = FFunc action = Create> <cfset FFunc.Path = "c:\"> <cfset FFunc.Mask = "*.*" > <cfset FFunc.attributes = 16 > <cfset x = FFunc.GetFileList()> <cfloop collection = #FFUNC# item = "file2"> <cfoutput> #file2.name# <br> </cfoutput> </cfloop> <!---Loop through a structure that is used as an associative array: ---> ... <!--- Create a structure and loop through its contents. ---> <cfset Departments = StructNew()> <cfset val = StructInsert(Departments, "John ", "Sales ")> <cfset val = StructInsert(Departments, "Tom ", "Finance ")> <cfset val = StructInsert(Departments, "Mike ", "Education ")> <!--- Build a table to display the contents ---> <cfoutput> <table cellpadding = "2 " cellspacing = "2 "> <tr> <td><b>Employee</b></td> <td><b>Dept.</b></td> </tr> <!--- Use item to create the variable person to hold value of key as loop runs. ---> <cfloop collection = #Departments# item = "person "> <tr> <td>#person#</td> <td>#StructFind(Departments, person)#</td></tr> </cfloop> </table> </cfoutput> |