I want to make a double loop with Do
. Let me first make a simple example. Consider the following simple double loop
Do[f[i,j]=i*j,{i,{1,2}},{j,{1,2}}]
does the job for $(i,j)=(1,1),(1,2),(2,1),(2,2)$ respectively. Now, suppose that I just want to do the same job but for $(i,j)=(1,1),(2,2)$. Clearly, one can use if statements inside Do
but I don't like such a solution since as the range of $(i,j)$ becomes large the process becomes time consuming. Also, if there is not any pattern for the range of loop indices $(i,j)$ then making use of if statements becomes complicated.
Now, let us express the general problem. Suppose that we have a random list for index $i$ and another random list for index $j$. I want to do a sequence of operations for each $(i,j)$ inside a Do
loop. What is the best way to do this?
Do[f[i,i]=i*i,{i,1,2}]
. Personally I would just store the numbers in a listflist=Table[i*i,{i,1,2}]
. $\endgroup$