title: How to use a for loop on a collection pulled from Magento
body: <p>im trying to use a for loop on products i pulled from Magento.
  And it crashes when i want to use the index on a product in the loop.</p>
  
  <pre><code>$collection = Mage::getModel('catalog/product')-&gt;getCollection();
  
  $collectionLength = count($collection);
  for($j = 0; $j &lt; $collectionLength; $j++)
  {
       $productFromStore = $collection[$j];//it crashes on this line of code
       $sku = $productFromStore-&gt;getSku();
  }
  </code></pre>
  
  <p>but when i use a foreach loop i can reach all the products.</p>
  
  <pre><code>foreach($collection as $product)
  {
       // this code works fine
       $sku = $product-&gt;getSku(); 
  }
  </code></pre>
  
  <p>Can someone explain what is going wrong and why?</p>
  
  <p>Thanks.</p>