It works fine for me - or at least it does exactly what I expect it to do:
Print "Press Y for continue and N for Exit"
Wait for me to type and press [ENTER]
Looks at the first character I type: If it is a upper of lower case 'Y' it repeats, otherwise it exits.
Have you tried typing "YYYYyyyyy" before you press [ENTER]?
Because you will find it loops 9 times if you do...
Basically, your code is looking for a reason to loop - the presence of a 'Y'. If it gets any other character, it exits. The [ENTER] key adds a '\n' character to the string, so when your code meets it, it exits the loop. You would be better off checking your inputs a bit more carefully!