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.
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,
^_^
Copy link to clipboard
Copied
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,
^_^