guys i am new to the arduino world and need your help !

i tried to combine the blink led and fade led programs to use them via my pc keyboard commands and switch between them as i like . but when i try to exit a current ongoing function the program runs once before coming to the choice input ! please help

int led = 9;
int brightness = 0;
int fadeAmount = 5;
int choice;

void setup() {

  Serial.begin(9600);       // starting Serial Communications with the board

  pinMode(led, OUTPUT);      //setting pin 9 to output mode
  pinMode(13, OUTPUT);       // switching off the onboard led on pin 13 which is lit by default
  digitalWrite(13, LOW);     // switching off the onboard led on pin 13 which is lit by default

  Serial.println("Welcome to LED Functions");
  Serial.println("");
  Serial.println("To Stop The Ongoing Function and To change your Choice Press 'X' ");
  Serial.println("");
  Serial.println("1 : Blinking Led");
  Serial.println("");
  Serial.println("2 : Fading Led");
  Serial.println("");
  Serial.println("3 : Manual ON/OFF");
  Serial.println("");

  Serial.setTimeout(10);    /* changing the waiting period for serial data flow to 10 milliseconds.
                              this helps in parseInt() function in which by default serial
                               data flows after 1 second so there is a little lag in the serial monitor */
}

void blinkFunction() {      // function for led blinking

digitalWrite(led, HIGH);
delay(900);
digitalWrite(led, LOW);
delay(900);
}

void fadeFunction() {     //function for led fading

  analogWrite(led, brightness);
  brightness = brightness + fadeAmount;
  if (brightness >= 255 || brightness <= 0) {
    fadeAmount = -fadeAmount;
  }
  delay(30);
}


void loop() {

  Serial.println("Please Enter Your Choice");
  Serial.println("xxxxxxx");   // print statement to see how the control is moving while the program runs
  
  while (Serial.available() == 0) {           // waiting for user to enter data
  }
  choice = Serial.parseInt();

  switch (choice) {

    case 1:
      Serial.println("LED is Blinking");

      while (Serial.available() <= 0) {
        blinkFunction();
      }
      digitalWrite(led, LOW);
      break;

    case 2:
      Serial.println("LED is Fading");

      while (Serial.available() <= 0) {
        fadeFunction();
      }
      digitalWrite(led, LOW);
      break;

  }
  
  Serial.println("yyyyyyy");   // print statement to see how the control is moving while the program runs
  
}

I would avoid parseInt and instead just parse the ASCII characters that come in. Change your case 1 statement to case '1', etc. and it will work. You also might want to deal with the carriage return and/or newline characters that will also come along.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

Also look at Planning and Implementing a Program. Note how each function runs very briefly and returns to loop() so the next one can be called. And there may be dozens of calls to a function before it is actually time for it to do anything.

...R