&& gives you true if both sides are true. otherwise it gives you false. So in order for "x && y" to be true, both x AND y must be true.
Loops continue looping as long as their loop condition is true.
Therefore...
while (rootBeer != -1 && heMan != -1)
tells the compiler "keep looping as long as rootBeer isn't -1 AND heMan isn't -1". As soon as either one of them becomes -1, then the AND condition becomes false, and the loop exits.
EDIT: to emphasize / clarify...
loop conditions are the condition for LOOPING, not for exiting. If you want to think of it as an exit condition instead, put the condition inside a ! operator:
1 2 3
|
while( condition_to_keep_looping )
// or...
while( !( condition_to_exit ) )
|
So if you want it to EXIT when both rootBeer and heMan are -1, then that's an exit condition:
while( !( rootBeer == -1 && heMan == -1 ) )
Which of course is the same as the following:
while( rootBeer != -1 || heMan != -1 )