Re: question on cfloop
Perhaps it only happened with qiery loops then Regards Russ Michaels www.michaels.me.uk www.cfmldeveloper.com - Free CFML hosting for developers www.cfsearch.com - CF search engine On Mar 1, 2013 10:00 PM, "Adam Cameron" wrote: > > On 1 March 2013 12:45, Russ Michaels wrote: > > > > > Have done so many times, many years ago thus how.discovered the issues. > > Unless it got fixed in current versions. > > > > Sorry mate, you're just mistaken. > > I dunno how far back you want to go, but I ran this code on CFMX7: > > > Before > > Within: #i# > > After #i# > > > And it outputs exactly what one would expect: > > Before > After 1 > > I cannot get CF5 to run on Windows 7, but I'd run the same on that, and get > the same results. I bet you a pint. > > -- > Adam > > > ~| 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:354774 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
On 1 March 2013 12:45, Russ Michaels wrote: > > Have done so many times, many years ago thus how.discovered the issues. > Unless it got fixed in current versions. > Sorry mate, you're just mistaken. I dunno how far back you want to go, but I ran this code on CFMX7: Before Within: #i# After #i# And it outputs exactly what one would expect: Before After 1 I cannot get CF5 to run on Windows 7, but I'd run the same on that, and get the same results. I bet you a pint. -- Adam ~| 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:354768 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: question on cfloop
>> It's the way index-based loops work. I am afraid that the way you described is not the way they work. The condition is evaluated before the loop starts and only commences if the condition is met. So will not run at all. >> Do you ever manipulate somearray inside the loop? That should not matter. The condition is evaluated once at the beginning of the loop. You can see this by running this code. #j#/ OUTPUT = 1/ X is evaluated at the start of the loop and not looked at again for the duration. >> I have a query on looping in coldfusion. Why does the below loop run twice? I suspect that the loop is either being called twice or your variable "#ArrayLen(somearray)# does in fact equal 2. Dennis Powers UXB Internet - A website Design and Hosting Company P.O. Box 6028, Wolcott, CT 06716 - T:203-879-2844 W: http://www.uxbinternet.com W: http://www.ctbusinesslist.com ~| 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:354760 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
Have done so many times, many years ago thus how.discovered the issues. Unless it got fixed in current versions. Regards Russ Michaels www.michaels.me.uk www.cfmldeveloper.com - Free CFML hosting for developers www.cfsearch.com - CF search engine On Mar 1, 2013 12:36 PM, "Adam Cameron" wrote: > > Just run the code & see, mate. > > On 1 March 2013 12:34, Russ Michaels wrote: > > > > > Yes Adam it does, I had to change much code back in the day due to that > > very issue. > > > > > ~| 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:354758 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
Sure. But you *don't need to*. deals with it. -- Adam On 1 March 2013 12:38, Russ Michaels wrote: > > Also it is quite easy to test if the dynamic.value will be above zero. > > E.g > > > Do loop > > Do something else > > > Regards > Russ Michaels > www.michaels.me.uk > www.cfmldeveloper.com - Free CFML hosting for developers > www.cfsearch.com - CF search engine > On Mar 1, 2013 12:26 PM, "Adam Cameron" > wrote: > > > > > On 1 March 2013 08:37, Russ Michaels wrote: > > > > > > > > The.simple answer is, only use an index loop where there is more than 1 > > > iteration. It will always run once even if the loop is 0, because it > has > > to > > > run once to find that out. > > > > > > > Nah, the condition is checked, but the code within the loop is not run > even > > once if the condition is not met: > > > > > > Before > > > > Within: #i# > > > > After #i# > > > > > > Output: > > Before > > After 1 > > > > As per the OP's situation, if the TO value is dynamic, one doesn't always > > know whether the loop will run zero, one or more times. So to say one > > should only use a loop when there's more than one iteration is a bit > > unreasonable. Anyway, the looping construct works fine no matter what > > combination of FROM/TO values you give it, so as long as you know how the > > thing works, it's safe to use it however one wants to. > > > > -- > > Adam > > > > > > > > ~| 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:354757 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
Also it is quite easy to test if the dynamic.value will be above zero. E.g Do loop Do something else Regards Russ Michaels www.michaels.me.uk www.cfmldeveloper.com - Free CFML hosting for developers www.cfsearch.com - CF search engine On Mar 1, 2013 12:26 PM, "Adam Cameron" wrote: > > On 1 March 2013 08:37, Russ Michaels wrote: > > > > > The.simple answer is, only use an index loop where there is more than 1 > > iteration. It will always run once even if the loop is 0, because it has > to > > run once to find that out. > > > > Nah, the condition is checked, but the code within the loop is not run even > once if the condition is not met: > > > Before > > Within: #i# > > After #i# > > > Output: > Before > After 1 > > As per the OP's situation, if the TO value is dynamic, one doesn't always > know whether the loop will run zero, one or more times. So to say one > should only use a loop when there's more than one iteration is a bit > unreasonable. Anyway, the looping construct works fine no matter what > combination of FROM/TO values you give it, so as long as you know how the > thing works, it's safe to use it however one wants to. > > -- > Adam > > > ~| 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:354756 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
Just run the code & see, mate. On 1 March 2013 12:34, Russ Michaels wrote: > > Yes Adam it does, I had to change much code back in the day due to that > very issue. > ~| 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:354755 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
Yes Adam it does, I had to change much code back in the day due to that very issue. Regards Russ Michaels www.michaels.me.uk www.cfmldeveloper.com - Free CFML hosting for developers www.cfsearch.com - CF search engine On Mar 1, 2013 12:26 PM, "Adam Cameron" wrote: > > On 1 March 2013 08:37, Russ Michaels wrote: > > > > > The.simple answer is, only use an index loop where there is more than 1 > > iteration. It will always run once even if the loop is 0, because it has > to > > run once to find that out. > > > > Nah, the condition is checked, but the code within the loop is not run even > once if the condition is not met: > > > Before > > Within: #i# > > After #i# > > > Output: > Before > After 1 > > As per the OP's situation, if the TO value is dynamic, one doesn't always > know whether the loop will run zero, one or more times. So to say one > should only use a loop when there's more than one iteration is a bit > unreasonable. Anyway, the looping construct works fine no matter what > combination of FROM/TO values you give it, so as long as you know how the > thing works, it's safe to use it however one wants to. > > -- > Adam > > > ~| 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:354754 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
On 1 March 2013 08:37, Russ Michaels wrote: > > The.simple answer is, only use an index loop where there is more than 1 > iteration. It will always run once even if the loop is 0, because it has to > run once to find that out. > Nah, the condition is checked, but the code within the loop is not run even once if the condition is not met: Before Within: #i# After #i# Output: Before After 1 As per the OP's situation, if the TO value is dynamic, one doesn't always know whether the loop will run zero, one or more times. So to say one should only use a loop when there's more than one iteration is a bit unreasonable. Anyway, the looping construct works fine no matter what combination of FROM/TO values you give it, so as long as you know how the thing works, it's safe to use it however one wants to. -- Adam ~| 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:354753 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
Because your output is on the outside of the loop, therefore 2 is expected. That is not an indication your loop is running twice, and to confirm that you will need to put the output inside the loop and you will see a big difference. Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/113032480415921517411 On Fri, Mar 1, 2013 at 11:46 AM, funand learning wrote: > > I am sorry, I wasn't clear. the "to" is arraylen. Sometimes the arraylen is > 1 > > > > > > #j# --this returns 2 > > On Thu, Feb 28, 2013 at 6:34 PM, Phillip Vector > 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 > > wrote: > > > > > > I have a query on looping in coldfusion.Why does the below loop run > > twice? > > > > > > > > >#j# > > > > > > > > > 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:354751 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
The.simple answer is, only use an index loop where there is more than 1 iteration. It will always run once even if the loop is 0, because it has to run once to find that out. I have never had an issue with an interation of 1 running twice though, that I have noticed anyway. Regards Russ Michaels www.michaels.me.uk www.cfmldeveloper.com - Free CFML hosting for developers www.cfsearch.com - CF search engine On Mar 1, 2013 3:10 AM, "Adam Cameron" wrote: > > > > > Do you ever manipulate somearray inside the loop? I am not sure if > > #ArrayLen(somearray)# is evaluated once or at each looping. > > > > The expressions passed to tags are evaluated first, then passed into the > tag code. So in this case it's not the expression "arrayLen(someArray)" > that's passed into the tag's code, it's the value of > "arrayLen(someArray)", for example "2". So the TO value is immutable once > it's first evaluated. > > A conditional loop is different, in that the string that is the condition > is passed into the code, not the result of it at the time the > tag is called, eg: > > > > > It's "someVar LE 3" that's passed to , not the result of "someVar > LE 3" (which would be TRUE initially). > > -- > Adam > > > ~| 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:354750 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
> > Do you ever manipulate somearray inside the loop? I am not sure if > #ArrayLen(somearray)# is evaluated once or at each looping. > The expressions passed to tags are evaluated first, then passed into the tag code. So in this case it's not the expression "arrayLen(someArray)" that's passed into the tag's code, it's the value of "arrayLen(someArray)", for example "2". So the TO value is immutable once it's first evaluated. A conditional loop is different, in that the string that is the condition is passed into the code, not the result of it at the time the tag is called, eg: It's "someVar LE 3" that's passed to , not the result of "someVar LE 3" (which would be TRUE initially). -- Adam ~| 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:354749 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
> 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. > Sorry mate, I strongly disagree with this. The index variable is * specifically* there to be used. Using an additional counter variable is just tautology. You say "if it isn't documented...", but it is. Clearly so: http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-71aa.html I would potentially agree that using it outside the loop (ie: after the end of it), might not be a good idea, because some languages only maintain the index variable within the loop code. That said, CFML is not one of those languages. -- Adam ~| 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:354748 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
It's the way index-based loops work. At the first pass of the , the INDEX variable is created with the initial value, and the condition (in this case the condition is an implicit "index variable value <= TO value"). If the condition is true, the loop block is entered. At the bottom of the loop block, execution is returned to the top of the block, the index variable is incremented by the STEP value (the default being 1), then the condition is evaluated again. If the condition is met, we're back into the loop block; if not, processing skips down to the first statement after the block. If you desk-check this, you will see that on the last iteration of the loop, the index value will be incremented beyond the bounds of the TO value, making the loop exit. So its final value will always - intrinsically - be higher than the TO value, by the amount of the STEP value. It's just how these things work. -- Adam On 1 March 2013 00:46, funand learning wrote: > > I am sorry, I wasn't clear. the "to" is arraylen. Sometimes the arraylen is > 1 > > > > > > #j# --this returns 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:354747 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
for (var j = 1; local.j lte ArrayLen(local.somearray); local.j++) { WriteOutput(local.j); } Steve 'Cutter' Blades Adobe Community Professional Adobe Certified Expert Advanced Macromedia ColdFusion MX 7 Developer http://cutterscrossing.com Co-Author "Learning Ext JS 3.2" Packt Publishing 2010 https://www.packtpub.com/learning-ext-js-3-2-for-building-dynamic-desktop-style-user-interfaces/book "The best way to predict the future is to help create it" On 2/28/2013 7:22 PM, fun and learning wrote: > I have a query on looping in coldfusion.Why does the below loop run twice? > > > #j# > > > 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:354745 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: question on cfloop
Do you ever manipulate somearray inside the loop? I am not sure if #ArrayLen(somearray)# is evaluated once or at each looping. -Original Message- From: listmas...@houseoffusion.com [mailto:listmas...@houseoffusion.com] On Behalf Of funand learning Sent: Thursday, February 28, 2013 4:47 PM To: cf-talk Subject: Re: question on cfloop I am sorry, I wasn't clear. the "to" is arraylen. Sometimes the arraylen is 1 #j# --this returns 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:354744 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
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 wrote: > > I am sorry, I wasn't clear. the "to" is arraylen. Sometimes the arraylen is > 1 > > > > > > #j# --this returns 2 > > On Thu, Feb 28, 2013 at 6:34 PM, Phillip Vector > 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 >> wrote: >>> >>> I have a query on looping in coldfusion.Why does the below loop run >> twice? >>> >>> >>> #j# >>> >>> >>> 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
Re: question on cfloop
I am sorry, I wasn't clear. the "to" is arraylen. Sometimes the arraylen is 1 #j# --this returns 2 On Thu, Feb 28, 2013 at 6:34 PM, Phillip Vector 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 > wrote: > > > > I have a query on looping in coldfusion.Why does the below loop run > twice? > > > > > >#j# > > > > > > 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:354742 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
not on Railo 4 is this the whole script? is it in at Custom Tag? On 1 March 2013 08:22, fun and learning wrote: > > I have a query on looping in coldfusion.Why does the below loop run twice? > > >#j# > > > 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:354741 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: question on cfloop
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 wrote: > > I have a query on looping in coldfusion.Why does the below loop run twice? > > >#j# > > > 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:354740 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
question on cfloop
I have a query on looping in coldfusion.Why does the below loop run twice? #j# 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:354739 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
question on cfloop
I have a query on looping in coldfusion.Why does the below loop run twice? #j# 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:354738 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm