So my understanding is that you loop over each character and then check it against every other character in the sequence.
When you check a new character, you need to reset 0 such that the counting can begin again.
eg.
for the letter "o" - c is set to 0, then it loops through each letter and increments c. At the end c is greater than or equal to 2 so the first loop continues.
the same is repeated for the second "o" (setting c to 0 again)
on the third character - c is set to 0 again and counting can begin, using the 2nd loop to look through the word again. This time c is less than 2 so it can return the result.
I used to find that if you sit with a pen and paper and work through the algorithm with the values you expect you will get a better understanding into the reason why. (Eventually for simple algorithms, you'll basically be able to do this in your head)