• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Invert Index Loop

Community Beginner ,
May 13, 2008 May 13, 2008

Copy link to clipboard

Copied

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.


TOPICS
Advanced techniques

Views

461

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 13, 2008 May 13, 2008

Copy link to clipboard

Copied

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=" -1". (ie decrease the index by 1 in each loop)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 13, 2008 May 13, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2008 May 13, 2008

Copy link to clipboard

Copied

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.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 14, 2008 May 14, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation