actionscript 3 - Why does uint break my for loop? -


this not problem fix simple , pretty costless. i'm guessing it's property of for or uint don't understand , know going on so...

using actionscript 3 set for loop run backwards through elements of vector.

var limit:uint = myvector.length-1; for(var a:uint = limit; >= 0; a--) {     trace(a); } 

when run outputs 2, 1, 0 expected moves on 4294967295 , begins counting down there until loop times out , throws error #1502.

the fix type a int rather uint don't why. surely dealing values of 0 , greater uint correct data type right?

i guess 4294967295 max value uint how count there?

if do

var myuint:uint = 0; trace(myuint - 1); 

then output -1 why, in loop should jump 4294967295?

sorry rambling question , cheers help.

you close. said, loop gives 2, 1, 0, 4294967295. because uint can't negative. loop run while a >= 0 , since never -1 break loop condition, continues loop forever.

var myuint:uint = 0; trace(myuint - 1); 

i didn't test happening myuint being converted int , having 1 subtracted. following code should able confirm this.

var myuint:uint = 0; trace((myuint - 1) uint); trace((myuint - 1) int); 

to fix loop use int or use for each(var x:type in myvector) loop if don't need index (a).


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -