Now my readers know that I've seen enough Coldfusion code in my day that I can quote some livedoc articles verbatim (including the notes and comments). It takes a great deal to surprise me with something new. But here's a snippet I found the other day that made me sit up and take notice. The fact that it uses CFLOOP (one of the most ho-hum of all the CF tags) is even more surprising. This is a loop that iterates over time increments. You can use it to create incremental time objects that are n number of minutes or seconds apart. It doesn't look like you might expect either. Here is an example that loops from 8 to 5 in 45 minute intervals:
The output:
Now you have to admit that's pretty neat - and pretty usefule too. You could easily see using this in a calendar application where you are scheduling appointments. It would let you add a drop down of available times. Nifty!
Before you get too excited and knock over your sippy cup you should know that this very useful bit of code is extremely expensive as loops go. It's roughly 50 times longer than the equivalent from="1" to="12" type loop. This is not a problem if you are building a single drop down or outputting a single bulleted list of times like the one above. But if you are going to run this loop over and over again you should know that it slows down drastically the more times you run it in a single request. I had a page where I was doing a "dateDiff()" call and examining a time element against the loop index like so: