It's not exiting the loop because it's checking for the "done" string before it ever retrieves the user input in the body of the loop.

In other words, at the point when it checks for "done" (i.e., just prior to entering the loop), link0 has been defined but nothing has been assigned to it yet because it hasn't reached cin. So it proceeds to run through the entire loop regardless of input received. It doesn't check for "done" again until after the loop restarts, i.e., after the 3rd cin.

A simple solution is to do the first cin before entering the loop. That way it is checking a variable that has received an assignment before running through its normal course, giving it the chance to exit if it receives "done."

Does that make sense?