The loop condition is tested on line 43 so when play is set to false on line 18 it will first run all the code between line 20 and 42 before exiting the loop.
the check for play is in the outer loop.
the inner loop will not stop until the player guesses the number...
you need
while (userGuess != randNum && userGuess)
which will fix it but is sort of a bandaid.
to correct it correctly you probably want to move the userguess/play logic into the innner loop and keep the while play on the outer loop as well, so that *both* loops end if they choose zero.