<?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"
	>
<channel>
	<title>Comments on: AS3 Tip: for loop index should not be uint</title>
	<atom:link href="http://blog.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.madebyderek.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>
	<pubDate>Thu, 29 Jul 2010 15:37:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Gaspy</title>
		<link>http://blog.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-28602</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-28602</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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-21953</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-21953</guid>
		<description>No it'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't because the index was of the type uint.

"In real life, you *should* be using INT if you expect your value to become negative, or use UINT"

... 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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-21941</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-21941</guid>
		<description>I don't understand, you'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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-19405</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-19405</guid>
		<description>thanks</description>
		<content:encoded><![CDATA[<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Vadneau</title>
		<link>http://blog.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-18635</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-18635</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't, so uint is not appropriate. In a positive moving index, as in my first example, the index never becomes negative so it'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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-18634</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-18634</guid>
		<description>maybe I'm totally missing something (ie the point) but why type a loop as uint, wouldn'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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-16035</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-16035</guid>
		<description>That's really not the same thing. You'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's of no advantage. In fact you'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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-16034</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-16034</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's something of a hack, I think.

This is my prefered way of doing it:

while ( list.length &#62; 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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-16031</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-16031</guid>
		<description>Huh. Well, now I know. Thanks for the explanation. Not intuitive but expected. I'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.madebyderek.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/#comment-16030</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-16030</guid>
		<description>Yes this is "expected" 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'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.madebyderek.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
