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

447

Likes

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,^_^

Likes

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,

^_^

Likes

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