Looping through structures

You can loop through a structure to output its contents, as the following example shows:

<!--- Create a structure and set 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>Department</b></td> 
    </tr> 
    <!--- Use cfloop to loop through the departments structure.  
    The item attribute specifies a name for the structure key. ---> 
    <cfloop collection=#departments# item="person"> 
        <tr> 
            <td>#person#</td> 
            <td>#Departments[person]#</td> 
        </tr> 
    </cfloop> 
</table> 
</cfoutput>