Problems with Switch Case

Im having some problems using switch case, I have 2 cases.Case S and case A. i want them to run individually but for some reason when i enter S in serial monitor, it runs my S then runs my A. when i enter A it only runs A.

  int Outputs[] = {3,4,5,6,8};
  int pwmpin = 13;
  void four();
  void twelve();
  void twenty();
  
  
void setup() 
{
  Serial.begin(9600);
 pinMode (Outputs[0], OUTPUT);
 pinMode (Outputs[1], OUTPUT);
 pinMode (Outputs[2], OUTPUT);
 pinMode (Outputs[3], OUTPUT);
 pinMode (Outputs[4], OUTPUT);
 pinMode (pwmpin, OUTPUT);
 
}


  int x=0;
  int checker=1;
  
  
  
  
void loop() {
  
 char data = Serial.read();
  
  switch (data) {
    case 'S':


  {
    Serial.println("Running DI");
    int x=0;
    
  
while(x<checker)
{
     digitalWrite(8, HIGH);
     delay(2000);
     digitalWrite(8, LOW);

     delay(10);
     
    Serial.println("X++");
        x++;
        
        
  }
  

  
 Serial.write("Done");
 break;
}

case 'A':

  
  {
    Serial.println("Running AI");
    four();
    delay(2000);
    twelve();
    delay(2000);
    twenty();
    Serial.write("Done");
  }
  }}

what's
wrong with
your

code

indentation?


I tried with dummy

void four() {}
void twelve() {}
void twenty() {}

functions as you did not provide them and for me it works and only run one or the other.

that being said, if your functions rely on the value of the global variable x to be changed in the 'S' case, then you have a problem because you are redefining that variable as a local scope one within your S case.

case 'S':
      {
        Serial.println("Running DI");
[color=red]        int x = 0;
[/color]        while (x < checker) {