title: foreach and non-parallel change of iterators
body: <p>I need to execute <em>foreach</em> with two iteration variables of the same size (for example <strong><em>1:n</em></strong>), but the function changes them in parallel as written <a href="http://cran.r-project.org/web/packages/foreach/vignettes/foreach.pdf" rel="nofollow">here</a>:</p>
  
  <blockquote>
    <p>We call a and b the iteration variables, since those are the variables that are changing during the multiple executions. Note that we are iterating over them in parallel, that is, they are both changing at the same time.</p>
  </blockquote>
  
  <p>What I need is to make foreach to change them independently, so that I would have a list with length <strong><em>n^2</em></strong>, not <strong><em>n</em></strong>.</p>
  
  <p>example:</p>
  
  <pre><code>X = foreach(i=1:n, j=1:n) %do% (sum(M[i,]*M[j,]))
  </code></pre>
  
  <p>in the end I get a vector of length <strong><em>n</em></strong> which is only a diagonal of matrix X, not the full matrix.</p>
  
  <p>P.S. I was trying to make this with <strong><em>for</em></strong> looping, but the computation time was too great to leave the code unoptimized.</p>