Please post your algorithm, we can't help you when we don't know what you're doing.

Small example of counting comparisons in a while-loop.

Code:
nr_of_comparisons = 0;
while (a != b) // the comparison
{
    nr_of_comparisons++;
    ....
}