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!
Tags: Actionscript, Learning

2 Comments add your own
Yep.
http://www.bit-101.com/blog/?p=908
Keith Peters | 21st November 2007 at 14:15
Ha, and I thought I was the only one who got caught out by this
nwebb | 12th April 2008 at 09:44
Leave a Comment comment policy
XHTML: you can use these tags - <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>Subscribe to the comments via RSS Feed