The test for # is inside the if that already established that key is 'B'. Key isn't read again in the while loop, hence the symptom you see.
The test for # is inside the if that already established that key is 'B'. Key isn't read again in the while loop, hence the symptom you see.