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

How to force my loop to start from position same as array?

Community Beginner ,
Sep 11, 2015 Sep 11, 2015

Copy link to clipboard

Copied

Hello everyone,

I'm working on my project and I have a problem looping through my array. As many of you know arrays in coldfusion start at position 1, inmy case if I put that my cfloop starts from 1 I'm getting an error because that does not match my array. Here is my sample of code:

<cfloop index="i" from="i-1" to=#(cnt)# step="1">

  <cfset myrow = #replace(myarray,chr(10),'')#>

  <cfset myrow = ListToArray(myrow,",",true)>

<cfoutput>

  (#myrow[1]#),

  (#myrow[2]#)

  <br/>

</cfoutoput>

</cfloop>

Does anyone know how I can fix this problem? I tried to use array in my loop but I got another error with that option.

Thanks in advance for any advise.

Views

515

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

correct answers 1 Correct answer

LEGEND , Sep 11, 2015 Sep 11, 2015

You don't want your array to start at 1?  But it looks as if you're trying to get it to start from 0, which is out of index range.

If you want your loop to start after the first position, then you need to calculate that position and have that as the from value.

<cfloop index="i" from="{calculated position}" to="#cnt#" step="1">

HTH,

^_^

Votes

Translate

Translate
LEGEND ,
Sep 11, 2015 Sep 11, 2015

Copy link to clipboard

Copied

LATEST

You don't want your array to start at 1?  But it looks as if you're trying to get it to start from 0, which is out of index range.

If you want your loop to start after the first position, then you need to calculate that position and have that as the from value.

<cfloop index="i" from="{calculated position}" to="#cnt#" step="1">

HTH,

^_^

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