<?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: AS3 Tip: for loop index should not be uint</title>
	<atom:link href="http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/</link>
	<description>Flash, SWF Studio, and the world around me</description>
	<lastBuildDate>Sat, 07 Jan 2012 22:51:17 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Gaspy</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-168</link>
		<dc:creator>Gaspy</dc:creator>
		<pubDate>Fri, 08 May 2009 13:07:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-168</guid>
		<description>I know this is old, but I just want to add something:
uint is slow; much slower than int.

You should use uint ONLY for doing bitwide operations like RGB values and stuff. For anything else, int/Number are more appropriate.</description>
		<content:encoded><![CDATA[<p>I know this is old, but I just want to add something:<br />
uint is slow; much slower than int.</p>
<p>You should use uint ONLY for doing bitwide operations like RGB values and stuff. For anything else, int/Number are more appropriate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Vadneau</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-163</link>
		<dc:creator>Derek Vadneau</dc:creator>
		<pubDate>Fri, 21 Dec 2007 15:00:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-163</guid>
		<description>No it&#039;s not *designed* to loop infinitely, it just happened to work that way. As I mentioned in the post I typically used uint for loops since I was expecting the number to always be positive. In the second case it needed to go negative but didn&#039;t because the index was of the type uint.

&quot;In real life, you *should* be using INT if you expect your value to become negative, or use UINT&quot;

... What? I should use INT, or use UINT? I was, that was the problem.

Anyhow, for all projects I now use Number instead of uint or int. Check out this link, originally posted in the article mentioned in the comments from Keith Peters:
http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/</description>
		<content:encoded><![CDATA[<p>No it&#8217;s not *designed* to loop infinitely, it just happened to work that way. As I mentioned in the post I typically used uint for loops since I was expecting the number to always be positive. In the second case it needed to go negative but didn&#8217;t because the index was of the type uint.</p>
<p>&#8220;In real life, you *should* be using INT if you expect your value to become negative, or use UINT&#8221;</p>
<p>&#8230; What? I should use INT, or use UINT? I was, that was the problem.</p>
<p>Anyhow, for all projects I now use Number instead of uint or int. Check out this link, originally posted in the article mentioned in the comments from Keith Peters:<br />
<a href="http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/" rel="nofollow">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-162</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 21 Dec 2007 00:03:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-162</guid>
		<description>I don&#039;t understand, you&#039;re code is designed to loop infinitely.

You *cannot* for a if( UINT = 0...

In real life, you *should* be using INT if you expect your value to become negative, or use UINT</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand, you&#8217;re code is designed to loop infinitely.</p>
<p>You *cannot* for a if( UINT = 0&#8230;</p>
<p>In real life, you *should* be using INT if you expect your value to become negative, or use UINT</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ivan</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-157</link>
		<dc:creator>ivan</dc:creator>
		<pubDate>Fri, 06 Jul 2007 18:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-157</guid>
		<description>thanks</description>
		<content:encoded><![CDATA[<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Vadneau</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-156</link>
		<dc:creator>Derek Vadneau</dc:creator>
		<pubDate>Wed, 13 Jun 2007 20:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-156</guid>
		<description>If the number is always positive, why would you use int?

In this case the index does NOT remain positive, or rather shouldn&#039;t, so uint is not appropriate. In a positive moving index, as in my first example, the index never becomes negative so it&#039;s fine. The problem was when the index moved in the negative direction.</description>
		<content:encoded><![CDATA[<p>If the number is always positive, why would you use int?</p>
<p>In this case the index does NOT remain positive, or rather shouldn&#8217;t, so uint is not appropriate. In a positive moving index, as in my first example, the index never becomes negative so it&#8217;s fine. The problem was when the index moved in the negative direction.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fleecie</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-155</link>
		<dc:creator>fleecie</dc:creator>
		<pubDate>Wed, 13 Jun 2007 19:48:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-155</guid>
		<description>maybe I&#039;m totally missing something (ie the point) but why type a loop as uint, wouldn&#039;t  int be more appropriate?</description>
		<content:encoded><![CDATA[<p>maybe I&#8217;m totally missing something (ie the point) but why type a loop as uint, wouldn&#8217;t  int be more appropriate?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Vadneau</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-153</link>
		<dc:creator>Derek Vadneau</dc:creator>
		<pubDate>Thu, 15 Feb 2007 20:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-153</guid>
		<description>That&#039;s really not the same thing. You&#039;re just clearing out the array. Using an index is useful when you are removing items from the array but not necessarily everything.

I tend to think of while loops as more dangeous, since you are responible for the exit condition. The while loop has its place, but in this case it&#039;s of no advantage. In fact you&#039;d end up with the same scenario if you were keeping track of the index.</description>
		<content:encoded><![CDATA[<p>That&#8217;s really not the same thing. You&#8217;re just clearing out the array. Using an index is useful when you are removing items from the array but not necessarily everything.</p>
<p>I tend to think of while loops as more dangeous, since you are responible for the exit condition. The while loop has its place, but in this case it&#8217;s of no advantage. In fact you&#8217;d end up with the same scenario if you were keeping track of the index.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-152</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Thu, 15 Feb 2007 20:05:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-152</guid>
		<description>Counting backwards with a for loop is always a bit tricky, it too many things that can go wrong. Someone suggested setting the length of the array to zero instead, and while this works, it&#039;s something of a hack, I think.

This is my prefered way of doing it:

while ( list.length &gt; 0 ) {
    list.pop();
}

Much more readable and more safe than the backwards for-loop.

Good warning though.</description>
		<content:encoded><![CDATA[<p>Counting backwards with a for loop is always a bit tricky, it too many things that can go wrong. Someone suggested setting the length of the array to zero instead, and while this works, it&#8217;s something of a hack, I think.</p>
<p>This is my prefered way of doing it:</p>
<p>while ( list.length &gt; 0 ) {<br />
    list.pop();<br />
}</p>
<p>Much more readable and more safe than the backwards for-loop.</p>
<p>Good warning though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Vadneau</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-151</link>
		<dc:creator>Derek Vadneau</dc:creator>
		<pubDate>Thu, 15 Feb 2007 18:15:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-151</guid>
		<description>Huh. Well, now I know. Thanks for the explanation. Not intuitive but expected. I&#039;ll definitely keep that in mind.</description>
		<content:encoded><![CDATA[<p>Huh. Well, now I know. Thanks for the explanation. Not intuitive but expected. I&#8217;ll definitely keep that in mind.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: senocular</title>
		<link>http://blog.tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-150</link>
		<dc:creator>senocular</dc:creator>
		<pubDate>Thu, 15 Feb 2007 18:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.madebyderek.com/?p=63#comment-150</guid>
		<description>Yes this is &quot;expected&quot; in that ECMAScript specifies calculations and expressions be handled using floating-point numbers.  The value obtained by trace is the value resulting from the expression, not i. This gives you the floating-point value prior to it being recast into a uint for the assignment back to i where the value /then/ becomes 4294967295.  Maybe not intuitive, but it&#039;s correct. :)</description>
		<content:encoded><![CDATA[<p>Yes this is &#8220;expected&#8221; in that ECMAScript specifies calculations and expressions be handled using floating-point numbers.  The value obtained by trace is the value resulting from the expression, not i. This gives you the floating-point value prior to it being recast into a uint for the assignment back to i where the value /then/ becomes 4294967295.  Maybe not intuitive, but it&#8217;s correct. <img src='http://blog.tracethis.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

