Question: how to deal with n " for...end do" loops

Hi, everyone.

I have got a question. There are n variables q[1],q[2],...q[n]. Each variable can take the value of 1,2, or 3, and I want get all the possible values of sum of these n variables,i.e. sum(q[i]...i=1..n). 
When n=2, I  write the procedure as follows:
    for q[1] from 1 to 3 do
      for q[2] from 1 to  3   do
         s[q[1],q[2]]:=sum(q[i],i=1..2);
      end do;
   end do;
If n is a very large number, then I have to write many "for..end do" loops, which is very unconvienient.

I wonder are there be some ways that by only changing the value of n, the task can be achevied.   

Please Wait...