title: Index out of range in for loop
body: <p>So I am working on a game, aside from a game engine, and I have a for loop to detect collisions with all objects in a list of Panels</p>
  
  <p>Here is the code:</p>
  
  <pre><code>for (int x = 1; x &lt;= 2; x++)
  {
      if (player.obj.Bounds.IntersectsWith(walls[x].Bounds))
      {
         MessageBox.Show("COLLIDING");
      }
  }
  </code></pre>
  
  <p>Currently there are only two objects added to the list called walls
  And everytime I go to run it tells me <code>Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index</code> I don't know what to do, am I setting up the if statement wrong?</p>
  
  <p>I just tried taking it out of the for loop and replaced x with 0, and when I touched that object it said I was colliding, so I know I didn't set up the if statement wrong.</p>