title: Nested For loop incrementing after termination
body: <p>I've got 2 for loops, one nested inside of another. They loop through a 2D array of buttons to get the source of each button thats been clicked using the action listener. </p>
  
  <p>When the button is found I pass the position/array indexs of the button to an external method. However when the button is found from the array of buttons the first for loop evaluates its termination condition to FALSE but still increments the value of i. Leading to an off by one error. My code is in the standard action performed method, with "event" being the ActionEvent. buttons[][] is a JButton array defined as an instance variable. It is of size 10 x 10 and is already added to the panel.</p>
  
  <pre><code>int i = 0; //this will loop through the columns in the array
  int j  = 0; //loop through the rows
  boolean locatedSource = false; //allows me to escape both loops
  
  for(i = 0; !(locatedSource) &amp;&amp; i &lt; buttons.length; i++) //problem here, when i &lt; buttons.length is FALSE i still gets incremented, leading to an off by one error
  {
    for(j = 0; !(locatedSource) &amp;&amp; j &lt; buttons.length; j++)
    {
      if(event.getSource() == buttons[i][j])
      {
        locatedSource = true;
        break;
      }
    }
  }
  //do stuff with i and j in another method. Leads to array out of bounds error / off by one error
  }
  </code></pre>
  
  <p>I should of mentioned, I'm not looking to solve this problem with the use of labels, they seem to be discouraged.</p>