Loop Over A Structure Using CFScript

Looping Over A Structure in CFScript is possible using the FOR ( key In Structure) Notation.

The following code demonstrates how to loop over a structure based on the keys existing in the structure;

[code:cf]
<cfscript>
myStruct = StructNew();
myStruct.FirstName = "Andrew";
myStruct.LastName = "Hall";
for(key in myStruct) {
writeOutput(key & " = " & myStruct[key] & "<br />");
}
</cfscript>
[/code]
Above Code Will Give The Following Output;

[code:cf]
FIRSTNAME = Andrew
LASTNAME = Hall
[/code]