title: Is a for-loop index counter stored in cache?
body: <p>So I have been thinking and reading about CPU cache optimization (on a MIPS R4000-like CPU specifically) and am wondering whether the for-loop <code>i</code> variable is stored in cache and whether this has consequences for what data inside the for-loop will be cached.</p>
  
  <p>Let's say I have an array containing the data I want to loop over. The data is tightly packed and should utilize the CPU cache nicely. Would there be a difference in these 2 ways of looping over this data?</p>
  
  <ol>
  <li>For loop using <code>i</code> index counter</li>
  <li>Terminating <code>null</code> as last item in the array</li>
  </ol>
  
  <p>Assuming 32-bits; would this mean that in case 1 I would have 4 bytes less to utilize on the cache since this is taken up by the index counter? Or would the counter be put in a register or something?</p>
  
  <p>I am relatively new and uneducated on this kind of optimization topic and I imagine that different optimization settings for the compiler would also impact this. I am curious to hear whether anyone has any info on this or can point me to a resource I could read to answer my question.</p>
  
  <p>Thanks,</p>