It might be beneficial to think of the 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 implies a loop nested within another, one loop for the rows and the other for the columns. This will give you the initial set of pairs:
{B1,A1} {B1,A2} {B1,A3} {B2,A1} {B2,A2} {B2,A3}
Then it is a matter of building up the combinations of that initial set. You can visualise the combinations similarly, with the set of pairs for both the rows and columns:
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| | | | | | |
-----+-----+-----+-----+-----+-----+-----+
Again this can be accomplished with a pair of nested loops (hint: your inner loop's range will be determined by the outer loop's value).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…