Nested for loop used to evaluate a two dimensional array of integers I am trying to use a nested for loop to evaluate and change numbers within the two dimensional array. Basically these numbers are minutes, or hours. This function is meant to reset the button controlled numbers when they go above 23 (hours) or above 59 (minutes) and also from going below 0. The two dimensional array that I made also has three arrays that need to be skipped (P1[0], P1[2] and P1[10] because they do not contain any time variables. When I click the buttons and increment the numbers nothing unusual happens they just don't bounce back like they are supposed to.

Here is the two dimensional array:

int P1[][12] = { //0-10
  {0}, //MODE
  {0, 0, 0, 0,}, //TOD variables
  // OnHR, OnMin, OffHr, OffMin
  {0}, //DOW
  {0, 0, 0, 0,},  //Sunday
  {0, 0, 0, 0,},    // OnHR, OnMin, OffHr, OffMin
  {0, 0, 0, 0,},
  {0, 0, 0, 0,},
  {0, 0, 0, 0,},
  {0, 0, 0, 0,},
  {0, 0, 0, 0,},  //Saturday
  {0, 0, 0, 0, 0,} // Temperature variables
  //Sensor, GreaterThan/LessThan, Temp, Buffer, State
};


Here is the for loop that doesn't seem to work:

void HrMinBounce() {
  int i = 0;
  int q = 0;

  for (int i; i &lt; 10; i++) { //iterating down Plug arrays
    for (int q; q &lt; 4; q++) {
      if (i != 0 || i != 2) { //non time arrays
        if (q == 0 || q == 2) { //hours
          if (P1[i][q] &gt; 23) {
            P1[i][q] = 0;
          }
          if (P1[i][q] &lt; 0) {
            P1[i][q] = 23;
          }
        }//End of hours
        if (q == 1 || q == 3) { //minutes
          if (P1[i][q] &gt; 59) {
            P1[i][q] = 0;
          }
          if (P1[i][q] &lt; 0) {
            P1[i][q] = 59;
          }
        }//End of minutes
      }
    }
  }
}


I have 5 of these arrays, so I was hoping to make one loop that could take care of all 5 at once. Here is my previous loop that works but I would have to copy and paste a whole lot to get the result without the extra for loop.

void MinHrLimit() {
  int i = 0;

  for (int i; i &lt; 3; i++) {
    if (i == 0 || i == 2) {
      if (P1[1][i] &gt; 23) {
        P1[1][i] = 0;
      }
      if (P1[1][i] &lt; 0) {
        P1[1][i] = 23;
      }
    }
  }
}
if(i != 0 || i != 2){ //non time arrays


Let's see.


If i is 0 then that is true (it isn't 2)
If i is 1 then that is true (it isn't 0 or 2)
If i is 2 then that is true (it isn't 0)
If i is 3 then that is true (it isn't 0 or 2)


In fact that expression is always true. You probably want:

            if(i != 0 &amp;&amp; i != 2){ //non time arrays




   void MinHrLimit(){
      int i = 0;

      for(int i; i &lt; 3; i++){


You don't need the declaration of i there, because it is redefined in the for loop. In the for loop the variable i has an undefined value. You really want:

   void MinHrLimit(){

      for(int i = 0; i &lt; 3; i++){