Question: How do I create a variable number of nested loops? (simple problem, but tricky)

Dear everyone,

I'm trying to create a list, L, of all vectors of length l with values in a small discrete set S (eg S:={1,2,3}). I can do this for any particular l by the following code:
(Assume l:=5)

L:=[]:
for i_1 in S do
for i_2 in S do
for i_3 in S do
for i_4 in S do
for i_5 in S do
                                        L:= [op(L), <seq(S[i_k],k=1..5)>];
od od od od od:

I want a code that can adapt to me putting in l=10, for example, at the beginning without having to copy and paste extra lines in. I am totally stumped on this. Any help would be greatly appreciated. Thanks for your time.

Rollo Jenkins.

Please Wait...