title: Objective-C loop through array
body: <p>I have code similar to this</p>
  
  <pre><code>if (count == 0)
  {
      [array1 addObject:@"No Items"];
  } 
  else
  {
      int x;
      for (x = 0;x &lt;= count; x++) 
      {
              [array1 addObject:[itemsArray objectAtIndex:x];
              NSLog(@"%@",array1);
      }
  }
  </code></pre>
  
  <p><code>itemsArray</code> has numbers in it (0-40). My expected result is:</p>
  
  <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>...</li>
  </ul>
  
  <p>However it actually does:</p>
  
  <ul>
  <li>1</li>
  <li>1,2</li>
  <li>1,2,3</li>
  <li>1,2,3,4</li>
  <li>1,2,3,4,5</li>
  <li>...</li>
  </ul>
  
  <p>Why does this happen? If possible, I'd also like to ask for an example to use fast enumeration for this situation (if it suits for this).</p>
  
  <p>Thanks in advance.</p>