View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfloop PreviousNext

cfloop

Looping is a programming technique that repeats a set of instructions or displays output repeatedly until one or more conditions are met. This tag supports the following types of loops:

Flow-control tags


Contents > CFML Reference > ColdFusion Tags > cfloop PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


MarkZet said on Apr 23, 2004 at 6:47 AM :
It would be very handy to have a <CFCONTINUE> tag (a familiar programming concept) that continues the loop from the beginning, in the next iteration.
halL said on Apr 23, 2004 at 7:23 AM :
There is an enhancement request (52228) oustanding for a cfcontinue tag.
We will be considering it for a future release.
Robert Gates said on Jun 11, 2004 at 4:03 PM :
How can I delay a loop for X number of seconds. Let's say I want to query a database over and over again without refreshing the page to check if there's new data in the database, but because I don't want to put too much stress on the database, I only want to do this ever 2 seconds. How is this possible?
jrunrandy said on Jun 14, 2004 at 8:27 AM :
rgates89: LiveDocs does not receive enough traffic to handle questions such as this
effectively. I suggest posting your issue to the online forums:
http://webforums.macromedia.com/coldfusion/ where, I'm sure, you will get
quite a few creative solutions. Also, I tried to send you an e-mail, but it bounced.
jakedimaredimare said on Jun 17, 2004 at 8:13 AM :
Can I place a loop inside another loop?
NCVision99 said on Jun 17, 2004 at 10:29 AM :
absolutely, do a google search for 'nested loop coldfusion' and you'll get a few sources or try http://livedocs.macromedia.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/arrayStruct4.htm this one explains the use with arrays
Mike@Jobscience said on Jun 24, 2004 at 3:09 PM :
I have noticed that looping through a query required a direct reference to the query variable rather than a returned refernce, such as:

<cffunction name="getQuery">
<cfreturn variables.myQuery> <!--- A previously created query --->
</cffunction>

<cfloop query="getQuery()">
--- output
</cfloop>

This does not work, at least not that I have been able to make it happen.
halL said on Jun 25, 2004 at 7:30 AM :
The code posted by Mike@Jobscience does not work for two reasons:

1) The function reference in the cfloop query attribute must be surrounded by pound signs.
The cfloop tag is treating "getQuery()" as a literal string, and there is no query named getQuery().

2) The cfloop query attribute requires the name of a query, not the query itself.
The getQuery() function returns the query, not its name.
If you fix problem 1, but not problem 2 the page generates a "Complex object types cannot be converted to simple values" error because it is trying to convert the query object to a string.

The following code does work as desired, but the function is not needed, since it just returns a hard-coded value that could be used directly as the cfloop query attribute.
(Note that this version of the code is not optimum CFML, as you can use cfoutput with a query attribute without using a cfloop.)

<cfquery name="myQuery" datasource="cfsnippets">
SELECT FirstName
FROM Employees
</cfquery>

<cffunction name="getQuery">
<cfreturn "myQuery"> <!--- A previously created query --->
</cffunction>
<cfoutput>
<cfloop query="#getQuery()#">
#FirstName#<br>
</cfloop>
</cfoutput>
mDgentry said on Nov 15, 2004 at 7:36 AM :
The CFLOOP logic is tested in the beginning of the loop. This could be considered DO-WHILE logic. It is possible that the routine within the CFLOOP could never be executed.

What tags exist to have the condition tested after the first execution of the routine. I need to always execute the loop at least one time. Can someone help me?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p76.htm