<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Riddle Me This, CFLOOP</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Justin Carter</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182407</link>
		<dc:creator>Justin Carter</dc:creator>
		<pubDate>Thu, 18 Jun 2009 22:18:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182407</guid>
		<description>I don&#039;t think the syntax could be much clearer - loop over the numbers from 1 to 10, and you can access the current index with &quot;i&quot;. If you need absolute control over the index then you should set it before the loop, use a condition for the looping, and manage the index yourself during the loop. Not all looping constructs are created equal, but they all have their uses :)</description>
		<content:encoded><![CDATA[<p>I don't think the syntax could be much clearer &#8211; loop over the numbers from 1 to 10, and you can access the current index with "i". If you need absolute control over the index then you should set it before the loop, use a condition for the looping, and manage the index yourself during the loop. Not all looping constructs are created equal, but they all have their uses :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182377</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Thu, 18 Jun 2009 16:26:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182377</guid>
		<description>@sean

While I see your point, I don&#039;t think syntax conveys that semantic very well.  (1..10).each { println it} (that&#039;s Groovy) clearly indicates that I&#039;m taking each number from 1 to ten and printing it, because I&#039;m iterating over a collection.  With the CFLOOP syntax, I read it as a verbose for loop (i.e. for (i = 1; i &lt;= 10; i += 1) { writeOutput(i) }), because stipulating a start and an end, not a collection of those values.  The step value also supports this understanding, I think.

Obviously that&#039;s NOT the behaviour, and it seems really weird in a CFML context.  I can&#039;t think of another place in the language where you have an implicit collection like that.  Even worse, there&#039;s no way to create such a collection excepting the implicit one inside a CFLOOP (which can&#039;t be accessed).</description>
		<content:encoded><![CDATA[<p>@sean</p>
<p>While I see your point, I don't think syntax conveys that semantic very well.  (1..10).each { println it} (that's Groovy) clearly indicates that I'm taking each number from 1 to ten and printing it, because I'm iterating over a collection.  With the CFLOOP syntax, I read it as a verbose for loop (i.e. for (i = 1; i <= 10; i += 1) { writeOutput(i) }), because stipulating a start and an end, not a collection of those values.  The step value also supports this understanding, I think.</p>
<p>Obviously that's NOT the behaviour, and it seems really weird in a CFML context.  I can't think of another place in the language where you have an implicit collection like that.  Even worse, there's no way to create such a collection excepting the implicit one inside a CFLOOP (which can't be accessed).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anthony</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182373</link>
		<dc:creator>anthony</dc:creator>
		<pubDate>Thu, 18 Jun 2009 15:14:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182373</guid>
		<description>oops.  lets try the code again.
&lt;cfloop from=&quot;1&quot; to=&quot;10&quot; index=&quot;i&quot;&gt;
  #i#&lt;br /&gt;
&lt;/cfloop&gt;
#i#</description>
		<content:encoded><![CDATA[<p>oops.  lets try the code again.<br />
&lt;cfloop from="1&#8243; to="10&#8243; index="i"&gt;<br />
  #i#&lt;br /&gt;<br />
&lt;/cfloop&gt;<br />
#i#</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anthony</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182372</link>
		<dc:creator>anthony</dc:creator>
		<pubDate>Thu, 18 Jun 2009 15:13:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182372</guid>
		<description>It seems as though cfloop resets the variable with every iteration of the loop, so once the loop starts over again, i gets reset.  What&#039;s strange to me is that i is local to each iteration, but once it breaks from the loop, i is no longer a local variable.  The following will out put &quot;11&quot; after the loop (which also doesn&#039;t make sense).


  #i#

#i#</description>
		<content:encoded><![CDATA[<p>It seems as though cfloop resets the variable with every iteration of the loop, so once the loop starts over again, i gets reset.  What's strange to me is that i is local to each iteration, but once it breaks from the loop, i is no longer a local variable.  The following will out put "11&#8243; after the loop (which also doesn't make sense).</p>
<p>  #i#</p>
<p>#i#</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Krug</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182361</link>
		<dc:creator>Jamie Krug</dc:creator>
		<pubDate>Thu, 18 Jun 2009 14:35:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182361</guid>
		<description>To be clear, both examples in my prior comment produce the following output:
1
2
3
7
8
9
10</description>
		<content:encoded><![CDATA[<p>To be clear, both examples in my prior comment produce the following output:<br />
1<br />
2<br />
3<br />
7<br />
8<br />
9<br />
10</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Krug</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182360</link>
		<dc:creator>Jamie Krug</dc:creator>
		<pubDate>Thu, 18 Jun 2009 14:33:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182360</guid>
		<description>Interesting. In cfscript, I guess since the conditions of the loop are more explicit, an equivalent loop produces different output:

for (i=1; i&lt;=10; i++) {
	writeOutput(i &amp; &#039;&#039;);
	if (i==3) i+=3;
}

@Sean: makes sense, but still a little odd to me. Even more strange that cfloop and cfscript-for behave so differently -- also makes sense, just odd. Another cfscript vs tags quirk, I guess.

Here&#039;s a tag-based alternative:

&lt;cfset i = 1 /&gt;
&lt;cfloop condition=&quot;i LTE 10&quot;&gt;
	#i#&lt;br /&gt;
	&lt;cfif i EQ 3&gt;
		&lt;cfset i += 3 /&gt;
	&lt;/cfif&gt;
	&lt;cfset i++ /&gt;
&lt;/cfloop&gt;

BTW, this also reminds me of a quirk I discovered a while back with grouped query output and the currentRow value. If you inspect the currentRow value within the inner cfoutput in a grouped query output, you&#039;ll find that it does not increment with inner loop iterations, but only the outer. I found this to be expected behavior. I can see both sides of the argument there.</description>
		<content:encoded><![CDATA[<p>Interesting. In cfscript, I guess since the conditions of the loop are more explicit, an equivalent loop produces different output:</p>
<p>for (i=1; i&lt;=10; i++) {<br />
	writeOutput(i &amp; ");<br />
	if (i==3) i+=3;<br />
}</p>
<p>@Sean: makes sense, but still a little odd to me. Even more strange that cfloop and cfscript-for behave so differently &#8212; also makes sense, just odd. Another cfscript vs tags quirk, I guess.</p>
<p>Here's a tag-based alternative:</p>
<p>&lt;cfset i = 1 /&gt;<br />
&lt;cfloop condition="i LTE 10&#8243;&gt;<br />
	#i#&lt;br /&gt;<br />
	&lt;cfif i EQ 3&gt;<br />
		&lt;cfset i += 3 /&gt;<br />
	&lt;/cfif&gt;<br />
	&lt;cfset i++ /&gt;<br />
&lt;/cfloop&gt;</p>
<p>BTW, this also reminds me of a quirk I discovered a while back with grouped query output and the currentRow value. If you inspect the currentRow value within the inner cfoutput in a grouped query output, you'll find that it does not increment with inner loop iterations, but only the outer. I found this to be expected behavior. I can see both sides of the argument there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randy Merrill</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182352</link>
		<dc:creator>Randy Merrill</dc:creator>
		<pubDate>Thu, 18 Jun 2009 12:59:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182352</guid>
		<description>From the livedocs:

http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_j-l_11.html#1101087

Note: The to value is evaluated once, when the cfloop tag is encountered. Any change to this value within the loop block, or within the expression that evaluates to this value, does not affect the number of times the loop is executed.

It is definately a little strange...</description>
		<content:encoded><![CDATA[<p>From the livedocs:</p>
<p><a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_j-l_11.html#1101087" rel="nofollow">http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_j-l_11.html#1101087</a></p>
<p>Note: The to value is evaluated once, when the cfloop tag is encountered. Any change to this value within the loop block, or within the expression that evaluates to this value, does not affect the number of times the loop is executed.</p>
<p>It is definately a little strange&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Scott</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182337</link>
		<dc:creator>Andrew Scott</dc:creator>
		<pubDate>Thu, 18 Jun 2009 09:50:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182337</guid>
		<description>@Sean, I disagree with you. Although this is what it is doing, one should be able to manually change the step value.

I wold file that as a bug, because that is exactly what it is.</description>
		<content:encoded><![CDATA[<p>@Sean, I disagree with you. Although this is what it is doing, one should be able to manually change the step value.</p>
<p>I wold file that as a bug, because that is exactly what it is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Corfield</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182332</link>
		<dc:creator>Sean Corfield</dc:creator>
		<pubDate>Thu, 18 Jun 2009 08:33:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182332</guid>
		<description>Not sure why you think this is unusual? You&#039;ve specified that the loop runs from 1..10. Changing the loop variable inside the loop is not going to affect the actual loop :)

Hint: it works like this in some other languages too (but not all/most).

So it depends on which languages you have exposure to...</description>
		<content:encoded><![CDATA[<p>Not sure why you think this is unusual? You've specified that the loop runs from 1..10. Changing the loop variable inside the loop is not going to affect the actual loop :)</p>
<p>Hint: it works like this in some other languages too (but not all/most).</p>
<p>So it depends on which languages you have exposure to&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2009/06/17/riddle-me-this-cfloop/comment-page-1/#comment-182323</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Thu, 18 Jun 2009 07:25:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1000#comment-182323</guid>
		<description>I fixed it for you.  I haven&#039;t figured out how to make WordPress be more rational about that.  Though I&#039;ll also admit I&#039;ve invested like 20 seconds of effort on it.  ;)</description>
		<content:encoded><![CDATA[<p>I fixed it for you.  I haven't figured out how to make WordPress be more rational about that.  Though I'll also admit I've invested like 20 seconds of effort on it.  ;)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
