Skip to Content


You (Level 0)
0% Complete
Last Badge Earned
None

In ColdFusion, loops are also quite a bit different from other languages in that their arguments look more like html attributes. However, I must first start out that telling you ColdFusion loops are one of my favorite things about ColdFusion. You can literally loop through anything in about any way that you want. You can loop through query results by just giving the loop the query name and a variable to increment. Alternatively, you can simply loop within ranges by giving ColdFusion the increment variable, starting point, ending point, and an index. Granted it isn't as cool as ColdFusion being able to query a query (we will get to this), but the flexibility of loops give ColdFusion a step up over other languages.

Example <cfoutput>
<cfloop index="x" from="1" to="10" step="1">
#x# <br/>
</cfloop>
</cfoutput>

The index argument is the variable you want to be involved in the loop. Usually, we will increment this variable by the step argument until we have ColdFusion return all the results that we wanted. from is your beginning value of x, and to is the finally result of x. The last argument below is the step, which is by how much do we want to increment the index.

Looping Query Results

Looping query results requires that you already know how to use ColdFusion to get results from an SQL server. What you need to do is to run a query first. Then that query will be an object that you can loop through. You just need to provide the query name and then you need some way to use each iteration to output a different record of the query. You can simply use an incrementing variable that can be defined in the initial loop statement. It is best to discuss this when we have an actual query to run.

Let's explore some more tutorials or topics!

Previous Tutorial Next Tutorial


If you enjoyed this resource, support me by sharing this page with others.

Comment on

No comments yet... Be the first!