function doSomething
{
  var i:int;
  for(i=0;i++;i<10)
  {
  }
}

Is functionally identical to this:

function doSomething
{
  for(var i:int =0;i++;i<10)
  {
  }
}

Wrong.  It's not.

In the latter example, i is not available after the loop.  In the first 
example, it is.

var i:int;
for (i = 0; i < 10; i++)
{
  if (i == 5) break;
}
trace(i);
-- 5

There are a multitude of uses for this, and I do it all the time.  
Additionally, I read somewhere many moons ago (back in my FLASM days) that 
declaring variables outside a for loop is less bytecode and uses less memory.  
I don't believe that applies to the counter declaration, but I do know it 
applies to the comparison as well as vars declared inside the for loop.  
However, this level of optimization is only useful in a practical way on mobile 
and some games.

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to