Not sure, but I believe the index at loop completion is incremented - that's 
how it knows how to stop. So it's similar to 

j=1;
while(j<2) {
        j++;
}


I've never used the loop index, and I don't think you should depend on it. Not 
sure what documented behavior is, but if it isn't documented in a specific way, 
it would be totally appropriate for it to go out of scope in a future version 
(kinda surprised it doesn't)

Instead, use your own counter var.

Billy Cravens
bdcrav...@gmail.com



On Feb 28, 2013, at 6:46 PM, funand learning <funandlrnn...@gmail.com> wrote:

> 
> I am sorry, I wasn't clear. the "to" is arraylen. Sometimes the arraylen is
> 1
> 
> <cfloop from="1" to="#ArrayLen(somearray)# index="j">
> 
> </cfloop>
> 
> <cfoutput>#j#</cfoutput> ----------this returns 2
> 
> On Thu, Feb 28, 2013 at 6:34 PM, Phillip Vector
> <vec...@mostdeadlygame.com>wrote:
> 
>> 
>> Why are you looping from 1 to 1? That isn't a loop.
>> 
>> On Thu, Feb 28, 2013 at 7:22 PM, fun and learning
>> <funandlrnn...@gmail.com> wrote:
>>> 
>>> I have a query on looping in coldfusion.Why does the below loop run
>> twice?
>>> 
>>> <cfloop from="1" to="1" index="j">
>>>   <cfoutput>#j#</cfoutput>
>>> </cfloop>
>>> 
>>> I thought the above code should return only 1, but it returns 1 2
>>> 
>>> 
>> 
>> 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:354743
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to