It might be useful to think of two arrays as sides of a table:
A1 A2 A3
---+-------+-------+-------+
B1 | B1,A1 | B1,A2 | B1,A3 |
---+-------+-------+-------+
B2 | B2,A1 | B2,A2 | B2,A3 |
---+-------+-------+-------+
This means that the loop is nested in another, one loop for rows and another for columns. This will give you an initial set of pairs:
{B1,A1} {B1,A2} {B1,A3} {B2,A1} {B2,A2} {B2,A3}
. , :
B1,A1 B1,A2 B1,A3 B2,A1 B2,A2 B2,A3
-----+-----+-----+-----+-----+-----+-----+
B1,A1| | X | X | X | X | X |
-----+-----+-----+-----+-----+-----+-----+
B1,A2| | | X | X | X | X |
-----+-----+-----+-----+-----+-----+-----+
B1,A3| | | | X | X | X |
-----+-----+-----+-----+-----+-----+-----+
B2,A1| | | | | X | X |
-----+-----+-----+-----+-----+-----+-----+
B2,A2| | | | | | X |
-----+-----+-----+-----+-----+-----+-----+
B2,A3| | | | | | |
-----+-----+-----+-----+-----+-----+-----+
(: ).