How to count the number of times a while loop is executed

Initialise a variable to 0, and increment it on every iteration?

int num = 0;

while (something) {
    num++;

    ...
}

printf("number of iterations: %d\n", num);

Leave a Comment