The web site for Flash ActionScript 3.0 game developers

 
         
   

Chapter 3, Reference Page 93, array difference?

Hello all, been am a fan of this book. Personally I think it is well thought out and very easy to follow. But I do have a question.

Reference Page 93

// make a list of card numbers
var cardlist:Array = new Array();
for(var i:uint = 0; i < boardWidth*boardHeight/2;i++)
{
cardlist.push(i);
cardlist.push(i);
}

What is the difference between the top code and the following code?
Is there any performance benefit?
Which is a better method to use?
Why?

Note: Please ignore the for() parameters, I have modified it to suit the question I am asking.
The question is directed towards the statements in the for loop.

for(var i:uint=0; i <(boardWidth*boardHeight/2)/2; i++)
{
carlist[i*2] = i;
cardlist[(i*2)+1] = i;
}



Copyright Gary Rosenzweig