The rule I follow (and one that I think is best for code readability) is that
you declare a variable the first time you use it. If you're using it in
multiple loops, you declare it above the first loop that uses it.
This is a trivial example:
private function foo(data:Array):void
{
var myVar:Boolean = true;
var i:int;
var len:int = data.length;
for (i = 0; i < len; ++i)
{
if (data[i] == "")
{
myVar = false;
break;
}
}
if (myVar)
{
for (i = 0; i < len; ++i)
{
trace(data[i].length);
}
}
}
If you're copying and pasting those loops around, you really should consider
learning how to write DRY code and use subroutines.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders