declare variables in for-statement
This works and traces '2' five times:
for (var i = 0; i < 5; i++)
{
var d:int = 2;
trace(d);
}
I sort of understand why this doesn't:
var d:int = 2;
trace(d);
var d:int = 2;
trace(d);
var d:int = 2;
trace(d);
var d:int = 2;
trace(d);
var d:int = 2;
trace(d);
Since I get the next error:
1151: A conflict exists with definition d in namespace internal
cause I declare the same variable five times.
The thing I don't understand is why it does work in the for-loop, since in principle I'm doing the same thing there. Why isn't it a problem for actionscript when I let the same variable be declared over and over again when I use a for-loop?
