title: C Programming, Loop difficulties
body: <p>I'm currently working on a problem and it's very annoying. It's a loop that I know how to do but trying to understand -WHY- the second case does not work. </p>
  
  <p>The first part is fine.</p>
  
  <pre><code>int n;
  int trianglenumber;
  trianglenumber = 0;
  for (n = 1; n &lt;= 200; n++)
      trianglenumber = trianglenumber + n;
  printf("%I,", trianglenumber");
  </code></pre>
  
  <p>Output is <code>20100</code></p>
  
  <pre><code>int n;
  int trianglenumber;
  trianglenumber = 0;
  int result = 0;
  for (n = 1; n &lt;= 200; n++)
      result = trianglenumber + n;
  printf("%I,", trianglenumber"); 
  </code></pre>
  
  <p>The program responds with the solution of <code>0</code> which I do not understand. Why do you need to use <code>trianglenumber</code> twice and then add it to <code>n</code>? Why can't you just set any variable to take the <code>trianglenumber</code>'s place like I did with result and get the same answer? Much appreciated. Just trying to figure this out. It's pretty basic I guess but I don't see it.</p>