title: Starting from j = i +1 vs j = 1 in a nested for loop
body: <p>For the piece of code below, I am using a vector that contains the items {1, 2, 3} and I just want to get the sum of the product of the pairs, for example (1*2) + (1*3) + (2*3) which is 11.</p>
  
  <pre><code>for(unsigned i = {0}; i &lt; vec.size(); ++i) {
      for(unsigned j = i + 1; j &lt; vec.size(); ++j) {
      //              ^^^^^^^            
          preresult = vec.at(i) * vec.at(j);
          result += preresult;
      }
  }
  </code></pre>
  
  <p>The problem is that, when I had in the inner loop <code>j</code> starting from 1, my answer was 30 and I got the right answer only when I changed to <code>j = i + 1</code>.</p>
  
  <p>Can someone explain to me why? Would not <code>j = 1</code> work just fine?</p>