Hello,
I tried to write some code on multiple but unknown number of loops. But didn’t find ways to do it. Can someone give me a hint? Thanks in advanced.
Suppose I have an array
a = [2,3,4,5]
I want to write a loop that is equivalent to the following
A = Array{Array{Int64}}(undef,0)
for i_1 in 1:a[1]
for i_2 in 1:a[2]
for i_3 in 1:a[3]
for i_4 in 1:a[4]
append!(A,[[i_1,i_2,i_3,i_4]])
end
end
end
end
output will be
A
144-element Array{Array{Int64,N} where N,1}:
[1, 1, 1, 1]
[1, 1, 1, 2]
[1, 1, 1, 3]
[1, 1, 1, 4]
[1, 1, 1, 5]
[1, 1, 2, 1]
[1, 1, 2, 2]
[1, 1, 2, 3]
[1, 1, 2, 4]
.
.
.
But in a more general way, so that it will also can deal with for other 1D arrays like
a = [2,3,4,5,6]
a = [2,3,4,5,6,7]
Baicai