I summarize the thought using my own word and understanding:

First we have two rules:

Rule 1. If A knows B: A must not be celebrity, B possible

Rule 2. If A doesn't know B: A possible, B must not be celebrity.

Using Rule 2, we have the first loop: if i doesn't know candidate, we put i as our potential candidate of celebrity:

for(int i=1; i<n; i++){
if ( !knows(i,candidate) ){
candidate = i;
}
}

In this loop we know two things:

Everything left of candidate ([0:candidates-1]) are not celebrity. (Because they 1. Either know someone or 2.They doesn't know anyone but someone doesn't know them as well!)
Everything right of candidate ([candidates+1:n]) knows candidate (otherwise candidate will be j where j falls in [candidates+1,n])

Notice that because of "2. Everything right of candidate ([candidates+1:n]) knows candidate ", we also conclude that everything right of candidate is not celebrity, proved by Rule 1. So from the first loop, the conclusion we can make is :

Every other person besides candidate MUST NOT be celebrity.

So now we just need to find out whether this candidate is celebrity, if it is, then it is; if not, then no one is celebrity in this party.

So we have the second loop whose only purpose is to find whether candidate is the celebrity. That's it.

Hope my explanation helps a little bit. :)