Counting how many times I've compared

I have the following for loop that compares some values before being entered:

1
2
3
4
5
for (;(loc > 0) && (theArray[loc-1 ]> nextItem); --loc){ 
		 counter++;
         // shift theArray[loc-1] to the right
         theArray[loc] = theArray[loc-1];
	  }


How can I keep track of how many times the for statement is hit? I mean, I know I would use a counter to keep track of how many times the loop is entered but what if the condition ((loc > 0) && (theArray[loc-1 ]> nextItem)) fails and I still want to make sure I count the comparison that happened?
How about this? Didn't test it but I guess it works.

1
2
3
4
5
int conditionCounter = 0;
for (;++conditionCounter, (loc > 0) && (theArray[loc-1 ]> nextItem); --loc)
{
    ....
}


Based on the comma operator (http://en.wikipedia.org/wiki/Comma_operator ).
Topic archived. No new replies allowed.