Serial.read issues

Serial.println("Input x");

while (Serial.available() == 0){}

x=Serial.parseInt();

Serial.println("Input y");

while (Serial.available() == 0){}

y=Serial.parseInt();

while (Serial.available() == 0){}

This is my code in void loop. I want the system to first ask for input x, then when received ask for input y, then when received proceed to the rest of the code. However, when implemented, the first time it is run, it will wait for x then ask for y. But then the next time it loops back, it displays "Input Y" almost immediately after "Input X". How can I solve this problem?

Hello
You may implement a FSM to go through the desired input steps.

By careful debugging, and handling the serial monitor's line-ending yourself