Infinite loops are great fun. Technically an infinite loop is one with no hope of ever stopping. In the old days(1995) I worked for an outfit with a database product for salvage yards. The whole thing was written in MUMPS and everything was done through a terminal. The first program I ever wrote myself was a "spinner" program. It ran on the terminal and produced the following characters 1/2 second apart - "/,|,-,\,|" the result was a little spinning widget on the terminal. I added some text that said "rebuilding dataset, please wait". Whenever we were working on something and needed a way to keep folks from hassling us with new issues we would put it up on the screen. It looked like it was really doing something. With an http request it's a different story however...
In web requests, infinite loops are generally bad. A web request is designed to run for short duration - in keeping with the stateless nature of http. Even though I've seen requests that run an hour or more by design (like a data import script) you should try to keep your request down below a few hundred milliseconds.
An infinite loop isn't just a really really long request however. Usually they are like that Chinese dragon that eats himself starting at the tail. They are created by folding a variable or object into itself - or by creating a condition that is never met. This often creates the unwelcome condition of memory growing and resources being consumed as the loop races to catch up with itself. This can be a great deal of fun and cause server administrators to run wildly through the data center throwing their hair back. I don't mean tossing their head like Fabio. I mean actually pulling out their hair and throwing it back behind them as they run. You can crash your server faster than a Hollywood marriage if you know what you are doing - or (especially) if you don't know what you are doing.
Other languages are actually more susceptible to infinite loops than Coldfusion. Why? One reason is the "cfloop" and "cfoutput" tag. Consider this ASP code:
Since there is no need to increment a variable CF makes it more difficult to fall into this trap. That's not to say you can't generate an infinite loop in CF. obviously you can do it with a "do while" or "conditional" loop that does not resolve the condition.
Here's one that will crash the server and it's harder to spot. In this code I want to run a series of calculations and store them in the "variables" scope. Then, I want to copy the values from the variables scope into an array, loop back and do the whole thing over again until I have an array of 10 containing all the variables from the variables scope. Sounds easy - right?
Why do it this way? I like this approach for outputting a variable number of columns (as apposed to rows). In most query driven output you know the number of columns and the rows are variable - but sometimes (like in an loan payment chart) you might now all the rows and it's the columns that are variable. In that case an array with defined structures and structure keys is a better choice because my output code can set the left hand label and loop n number of times based on the length of the array.
In any case, not only will this code not run, but it will crash the server. You may have spotted the flaw in my loop already. The variable "tblArr" is an array that exists in the variables scope. When the loop reaches the variable "tblArr" it is going to try to set a reference to itself (tblArr[tblArr] = tblArr). This is going to grind the code to a halt and set the processor spinning. Remember that Chinese snake?
Instead, the code should have been written like this: