What is this loop doing?  I can't understand the else condition specifically.