I'm porting some JavaScript to Java and I'm having a hard time understanding two lines of the following piece of code:
var blocks=[];
for (var z=0; z<size; z++) {
var slice=blocks[z]=[]; //Those are the lines I don't understand.
for (var x=0; x<size; x++) {
var row=slice[x]=[]; //Those are the lines I don't understand.
for (var y=0; y<size; y++) {
row[y]=isFull(x,y,z);
}
}
}
The first line is declaring "slice", then it assigns "blocks[z]", and then again it assigns an empty array.
As I'm writing this it came to my head that maybe is for clearing any previous info before assigning new data, but I'm not sure.
Actually an empty array is assigned to blocks[z]
, and the value of blocks[z]
(the empty array) is then assigned to slice
.
Basically it's just a short way of assigning a value to two (or more) variables