Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Foreach loop
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== ColdFusion Markup Language (CFML) === {{Main|ColdFusion Markup Language}} ==== Script syntax ==== <syntaxhighlight lang="cfs"> // arrays arrayeach([1,2,3,4,5], function(v){ writeOutput(v); }); // or for (v in [1,2,3,4,5]){ writeOutput(v); } // or // (Railo only; not supported in ColdFusion) letters = ["a","b","c","d","e"]; letters.each(function(v){ writeOutput(v); // abcde }); // structs for (k in collection){ writeOutput(collection[k]); } // or structEach(collection, function(k,v){ writeOutput("key: #k#, value: #v#;"); }); // or // (Railo only; not supported in ColdFusion) collection.each(function(k,v){ writeOutput("key: #k#, value: #v#;"); }); </syntaxhighlight> ==== Tag syntax ==== <syntaxhighlight lang="CFM"> <!--- arrays ---> <cfloop index="v" array="#['a','b','c','d','e']#"> <cfoutput>#v#</cfoutput><!--- a b c d e ---> </cfloop> </syntaxhighlight> CFML incorrectly identifies the value as "index" in this construct; the <code>index</code> variable does receive the actual value of the array element, not its index. <syntaxhighlight lang="CFM"> <!--- structs ---> <cfloop item="k" collection="#collection#"> <cfoutput>#collection[k]#</cfoutput> </cfloop> </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)