Newest Visitor Badge Earned!
Click to create an account and start competing today!
After Hours Programming
Show Tutorials

You (Level 0)
Last Badge Earned
Newest Visitor

ColdFusion Loop Statements Tutorial

ColdFusion Loop Statements

The ColdFusion Loop Statements tutorial explains how to use loops in ColdFusion. Loops are a little bit different in ColdFusion, which makes it important to know the distinction.

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/>

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 move on to some more tutorials or the next section!

Previous Tutorial


Next Tutorial


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

Stumbleupon Facebook Twitter GooglePlus Reddit Delicious Digg

Comment or Suggestion?

Comments are a way to tell me about corrections or suggestions, what you thought about the resource, or providing additional information. Help feed the discussion!


Comments on ColdFusion Loop Statements

No comments yet... Be the first!