Variable Counting

What code can I use to count how many times a certain variable is equal to 0? Also, when the variable does not equal 0, I need the counter to restart.
Thank you

Make sure you declare all the variables at the top.

if( someVar == 0)
counter++;
else
counter = 0;

Its not rocket science.

int variable=0;
int counter=0;
void loop(){
  if (variable==0) {
    counter ++; 
  } else {
    counter=0;
  }
 // some code, which can set or unset variable
}