"while()" statement won't exit

Apparently, you read the state of a pin before the while statement starts. Once it starts, you never read the state of the pin again, so the pin can change state a million times, and you'll never know.

Obviously, you need to read the state of the in IN the body of the while statement.