Second call to Serial.available() doesn't work

Second call to Serial.available() works if user entered data is assigned to integer variable but doesn't work if user entered data is assigned to string variable.

String name;
String Mobile;

void setup() {
  Serial.begin(115200);

  Serial.println("Enter your name");
  while (Serial.available() == 0) { } // wait for input from user
  name = Serial.readString();  // read input from serial port

  Serial.println("Enter your mobile number");
  while (Serial.available() == 0) { } // wait for input from user
  Mobile = Serial.readString();  // read input from serial port

Output is as follows:
Enter your name
Enter your mobile number

Execution of code is halted, waiting for user to enter mobile number. That's the correct behavior.

Now consider above program modified to assign user entered data to integers.

int num1;
int num2;

void setup() {
  Serial.begin(115200);

  Serial.println("Enter first number");
  while (Serial.available() == 0) { } // wait for input from user
  num1 = Serial.parseInt();  // read input from serial port

  Serial.println("Enter second number");
  while (Serial.available() == 0) { } // wait for input from user
  num2 = Serial.parseInt();  // read input from serial port

  Serial.println("----------------------------");  // showing the details
  Serial.println(num1);
  Serial.println(num2);

Output is as follows:
Enter first number
Enter second number

1
0

When prompted to enter first number, I entered 1. Before I had chance to enter second number, program execution was completed.

Why does above code work for strings but not integers?

What happened to the line of -------?

Did you consider the presence of carriage-return/ line-feed?

What have you got Line Ending set to in the Serial monitor ?

This stuff really needs a sticky.
At least the second time today.

Along with at least a dozen other common problems that will not bother reading about

Sad, but true.

The output is as follows:

Enter first number
Enter second number

1
0

The output is as follows:

type or paste Enter first number
Enter second number
----------------------------
1
0
code here

Line ending in serial monitor is set to Newline.

If you have a Line ending set then that character will still be available() after the first reply has been read, hence answering the second question without waiting. Try setting the Line ending to "No line ending"

I changed Line ending setting to "No line ending". Now, second call to Serial.available() waits for user to enter data. Thank you!

When Line ending is set to "Newline", second call to Serial.available() should behave same whether data input by user will be assigned to integer variable or string variable?

Serial.readString() will include the newline as part of the String, which is a common problem when the String is subsequently compared to text that does not contain the \n at the end. Serial.parseInt() terminates when a character that is not part of the number is encountered.