Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / May 2008



Tip: Looking for answers? Try searching our database.

Invert Index Loop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jellyhead - 13 May 2008 15:42 GMT
So I've got a dumb q again...

<cfloop index="q" from="-5" to="5">

works perfectly and gives me numbers from -5 to 5.  Counts up.  

How can I make it loop / output the other way, from 5 to -5.  Counts down?

This must be so easy, yet it escapes me.  Its been a long day -  forgive me.
-==cfSearching==- - 13 May 2008 15:49 GMT
Use the "step" attribute.  The default is step="1" (ie increment by positive 1).  You can cause the loop to "count down" by using step="[b]-1[/b]".  (ie decrease the index by 1 in each loop)
Jellyhead - 13 May 2008 15:58 GMT
Great - thanks - so easy.  there you have it folks.
But remember to then swap the "to and "From" values as well.

<cfloop index="q" from="5" to="-5" step = "-1">
Adam Cameron - 13 May 2008 16:41 GMT
It's also perhaps worth remembering all this sort of thing is a mouseclick
away, in the documentation:

http://livedocs.adobe.com/coldfusion/8/Tags_j-l_11.html

You don't need to waste time sitting there wondering how to do it, or
trying different stuff, or wait for people to come back to you via the
forums (although they were pretty quick, this time): you can help yourself,
via the docs.

Signature

Adam

-==cfSearching==- - 14 May 2008 13:03 GMT
Adam Cameron wrote:
> It's also perhaps worth remembering all this sort of thing is a mouseclick
> away, in the documentation:

Yes, another good resource is http://cfquickdocs.com/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.