I'm trying to count the number of 0's that occur in an array of 0's and 1's. If half of the array is 0, I keep it. If not, I change it. I start counting on the 2nd digit (index 1) for convenience. I'm not concerned with index 0 and don't count it. I'm not sure why I'm getting an infinite loop with this.. could it be the equality in 

```
 if (z == 4){
      g = 1;
    }

```

---

```
#include "stdlib.h"
#include "stdio.h"

int main(){
  int i, j, z, g;
  z = 0;
  int ar[9] = {0,0,0,0,0,0,0,0,0};
  g = 0;
  while(!g){
    for(i = 1; i < 9; i++){
      printf("%d", ar[i]);
      if (ar[i] == 0){
        z++;
      }
    }
    if (z == 4){
      g = 1;
    }
    else {
      for (i = 1; i < 5; i++){
        ar[i] = 0;
      }
      for (i = 5; i < 9; i++){
        ar[i] = 1;
      }
    }
  }
  printf("\n %d", z);
  return 0;
}

```