title: C - linked-lists for loop doubts
body: <p>I am unsure on which way to dealloc my <code>list</code> of <code>Item</code>. Each <code>list</code> has a first and last item, and each <code>item</code> is linked to a <code>nextItem</code> until it is null.</p>
  
  <pre><code>for(myItem=list.firstItem; myItem!=list.lastItem; myItem=myItem-&gt;nextItem)
      dealloc(myItem);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>for(myItem=list.firstItem; myItem!=NULL; myItem=myItem-&gt;nextItem)
      dealloc(myItem);
  </code></pre>
  
  <p><code>myItem-&gt;nextItem = NULL</code> if <code>myItem=list.lastItem</code>.</p>
  
  <p>I am unsure if using the first declaration of the for will dealloc all of  <code>myItem</code> or if the lastItem will not be dealloc. (I believe this is what will happen.)
  On the other hand, i am unsure if the second declaration will make everything crash/not work properly when you assign to <code>NULL</code>a <code>myItem</code>.</p>