Reputation: 39
I have a problem I'm not sure how to solve. I need to change the name of the array being used in the loop to the next consecutive one. ie array xor1[] in first iteration then xor2[] in next and so on.
int xor1[] = {0,1,1,0,1,1};
int xor2[] = {0,1,1,1,0,1};
for(int ii = 0; ii < 2; ii++)
{
int[] row = new int[2];
//xor1 in next iteration should be xor2???
row[0] = xor1[0];
row[1] = xor1[5];
}
Note: there is far more than 2 iterations this is just for simplicity.
Upvotes: 0
Views: 51
Reputation: 159086
Create an array of the arrays, then iterate that.
int[] xor1 = {0,1,1,0,1,1};
int[] xor2 = {0,1,1,1,0,1};
int[][] xors = {xor1,xor2};
for (int[] xor : xors) {
int[] row = new int[2];
row[0] = xor[0];
row[1] = xor[5];
}
Upvotes: 3