Using uint as a loop iterator
21st November 2007
It took me some time to track down this bug in some code recently. I post it here to help others avoid the error. It’s obvious once you see it. When does this loop stop?
for( var i:uint = 5; i >= 0; i-- )
{
// do something here
}
The answer, of course, is never. The loop continues indefinitely because a uint can never be less than 0. Doh!
Read more articles about Actionscript 3
2 Comments add your own
Yep.
http://www.bit-101.com/blog/?p=908
:)
Keith Peters | 21st November 2007 at 2:15 pm
Ha, and I thought I was the only one who got caught out by this :)
nwebb | 12th April 2008 at 9:44 am
Leave a Comment
XHTML: you can use these tags - <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>Subscribe to the comments via RSS Feed