« Actionscript 3 Training in the UK | Actionscript 3 tetris source code »

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

Leave a Comment

required

required, hidden

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