Bryan,
A foreach loop is a specialized conditional loop that states to loop for
each item in a collection.
A conditional loop over a list looks something like this:
<cfset idx = 1>
<cfset length = listLen(somelist)>
<cfloop condition="idx LTE length">
<!--- do something --->
<cfset idx = idx + 1>
</cfloop>
An iterative loop over a list looks like this:
<cfset length = listLen(somelist)>
<cfloop index="idx" from="1" to="#length#">
<!--- do something --->
</cfloop>
A foreach-like loop looks like this:
<cfloop index="idx" list="#somelist#">
<!--- do something --->
</cfloop
There is another CFLOOP that functions much like the last example for
handling the elements in a structure of the items in a COM collection.
Other languages actually use a statement called "foreach" to handle most
kinds of collections (whether they be datatypes like lists or arrays or
structures or higher order collections).
rish
-----Original Message-----
From: Bryan Stevenson [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 11, 2004 11:04 AM
To: CF-Talk
Subject: Re: "foreach"?
What is a "foreach" loop? Do you mean a conditional loop (i.e. for each
iteration test a condition and if met break out of the loop)? If so...yes
;-)
Bryan Stevenson B.Comm.
VP & Director of E-Commerce Development
Electric Edge Systems Group Inc.
phone: 250.480.0642
fax: 250.480.1264
cell: 250.920.8830
e-mail: [EMAIL PROTECTED]
web: www.electricedgesystems.com
[Todays Threads]
[This Message]
[Subscription]
[Fast Unsubscribe]
[User Settings]
[Donations and Support]
- "foreach"? Damien McKenna
- Re: "foreach"? Bryan Stevenson
- Re: "foreach"? Guy Rish
- Re: "foreach"? Bryan Stevenson
- RE: "foreach"? Marlon Moyer
- Re: "foreach"? Damien McKenna
- RE: "foreach"? Spike
- RE: "foreach"? Benjamin S. Rogers
- Re: "foreach"? Ewok
- CFCHART Macromedia page broke Ewok
- Re: CFCHART Macromedia page broke Bryan Stevenson