<?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: ActionScript 3 Loops</title>
	<atom:link href="http://jacksondunstan.com/articles/5/feed" rel="self" type="application/rss+xml" />
	<link>http://jacksondunstan.com/articles/5</link>
	<description>Mastering AS3</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:25:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/5/comment-page-1#comment-48</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Sat, 19 Sep 2009 17:24:42 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=5#comment-48</guid>
		<description>Oh, it&#039;s definitely the most flexible loop. It also involves the most typing, both on the keyboard and as far as data types. Almost all of my C-style for loops involve an explicit cast where I cache the current value. You&#039;re right about the mixed-type problem though. In this case you&#039;re forced into using the &lt;tt&gt;is&lt;/tt&gt; operator like this:

&lt;pre lang=&quot;actionscript3&quot;&gt;
var len:int = someArray.length;
for (var i:int = 0; i &lt; len; ++i)
{
  var cur:* = someArray[i];
  if (cur is Point)
  {
    var p:Point = cur as Point;
    // do stuff with the point here...
  }
  else if (cur is Matrix)
  {
    var m:Matrix = cur as Matrix;
    // do stuff with the matrix here...
  }
}
&lt;/pre&gt;

It&#039;s worth noting that you don&#039;t have an option here: C-style loops give you the flexibility you &lt;em&gt;need&lt;/em&gt; because there&#039;s no super class of Point and Matrix that&#039;s useful (Object doesn&#039;t count).

Thanks for the comment!</description>
		<content:encoded><![CDATA[<p>Oh, it&#8217;s definitely the most flexible loop. It also involves the most typing, both on the keyboard and as far as data types. Almost all of my C-style for loops involve an explicit cast where I cache the current value. You&#8217;re right about the mixed-type problem though. In this case you&#8217;re forced into using the <tt>is</tt> operator like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> len<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = someArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> len<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> cur<span style="color: #000066; font-weight: bold;">:*</span> = someArray<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>cur <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> p<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span> = cur <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #009900; font-style: italic;">// do stuff with the point here...</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>cur <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> m<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = cur <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Matrix</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #009900; font-style: italic;">// do stuff with the matrix here...</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It&#8217;s worth noting that you don&#8217;t have an option here: C-style loops give you the flexibility you <em>need</em> because there&#8217;s no super class of Point and Matrix that&#8217;s useful (Object doesn&#8217;t count).</p>
<p>Thanks for the comment!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://jacksondunstan.com/articles/5/comment-page-1#comment-47</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Sat, 19 Sep 2009 16:17:04 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=5#comment-47</guid>
		<description>In Actionscript, when using the C-style loop, casting the accessed array item will allow for run-time errors and code completion.

If the items in the array are of mixed type, this would be less helpful - unless you are able to cast to a super class.</description>
		<content:encoded><![CDATA[<p>In Actionscript, when using the C-style loop, casting the accessed array item will allow for run-time errors and code completion.</p>
<p>If the items in the array are of mixed type, this would be less helpful &#8211; unless you are able to cast to a super class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tweets that mention ActionScript 3 Loops « JacksonDunstan.com -- Topsy.com</title>
		<link>http://jacksondunstan.com/articles/5/comment-page-1#comment-15</link>
		<dc:creator>Tweets that mention ActionScript 3 Loops « JacksonDunstan.com -- Topsy.com</dc:creator>
		<pubDate>Wed, 16 Sep 2009 18:20:11 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=5#comment-15</guid>
		<description>[...] This post was mentioned on Twitter by Franky. Franky said: for each (var item in list) seems to &quot;cache&quot; list, probably on the stack. http://bit.ly/11OSLu (via @robpenner) [...]</description>
		<content:encoded><![CDATA[<p>[...] This post was mentioned on Twitter by Franky. Franky said: for each (var item in list) seems to &quot;cache&quot; list, probably on the stack. <a href="http://bit.ly/11OSLu" rel="nofollow">http://bit.ly/11OSLu</a> (via @robpenner) [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

