CFLoop index Can't Handle Countdown

I just noticed something strange with CFLoop Index. Looks like Lucee’s implementation of cfloop isn’t able to handle countdown/decreasing indexes.

Something like the below:

<cfloop index="i" from="10" to="1">

This will produce nothing on Lucee (basically Lucee doesn’t loop through it) while Coldfusion can handle both incremental/decremental index loops.

Of course, we can use a workaround like:

<cfset MyNum = 10>
<cfloop index="i" from="1" to="10">
<cfoutput>#Evaluate(MyNum - DecrementValue(i))#<br></cfoutput>

However, just thought I’d raise this here regarding this behaviour on Lucee. I’m using the latest stable version of Lucee.

Java: 1.8.0_121


Charles Tang

The code you’ve used doesn’t appear to be showing… But are you including the step="-1" attribute as it seems to work OK on trycf…

Thanks a lot @jedihomer. Yes, you’re right. Adding step="-1" works well. My mistake! A bit of a brain fart moment. :grin: Sorry about that.

Thanks for the tip!