Motor controll through serial port

Hi guys, I want to make a program for controling my robot through my pc. I use bluetooth module. Arduino recieves and sends data just fine. The problem is that I can't figure out how to write a program for arduino that my motors would be running as long as im pressing the button, the moment i am not pressing the button they would not move, so basically I need to clean up the data after every loop but that's not working.... Maybe someone can help me? My code is:

int MOTOR_B_PWM = 9;
int MOTOR_B_DIR = 8;
int MOTOR_A_PWM = 6;
int MOTOR_A_DIR = 7;
char data = 0;

void setup()
{
  Serial.begin( 9600 );
  pinMode( MOTOR_B_DIR, OUTPUT );
  pinMode( MOTOR_B_PWM, OUTPUT );
  pinMode( MOTOR_A_DIR, OUTPUT );
  pinMode( MOTOR_A_PWM, OUTPUT );
  digitalWrite( MOTOR_B_DIR, LOW );
  analogWrite( MOTOR_B_PWM, LOW );
  digitalWrite( MOTOR_A_DIR, LOW );
  analogWrite( MOTOR_A_PWM, LOW );
}
void loop() {
 serial();
 control();
 delay(100);
   
    
  }
  
  
  void serial() {
   if (Serial.available() > 0 ) {
    data = Serial.read(); }
  
  }
  
  void control() {
    switch(data)
    {
   case 'w':
   digitalWrite(MOTOR_B_DIR, HIGH);
      analogWrite(MOTOR_B_PWM, 100);
      digitalWrite(MOTOR_A_DIR, HIGH);
      analogWrite(MOTOR_A_PWM, 100);
      Serial.println("on");
      data='*';
      
      break;
      
      case 'z':
      digitalWrite(MOTOR_B_DIR, LOW);
      digitalWrite(MOTOR_B_PWM, LOW);
      digitalWrite(MOTOR_A_DIR, LOW);
      digitalWrite(MOTOR_A_PWM, LOW);
      Serial.println("off");
      data='*';
      break;
    }
  
  
  }

and I also tried this one:

int MOTOR_B_PWM = 9;
int MOTOR_B_DIR = 8;
int MOTOR_A_PWM = 6;
int MOTOR_A_DIR = 7;
char data = 0;

void setup()
{
  Serial.begin( 9600 );
  pinMode( MOTOR_B_DIR, OUTPUT );
  pinMode( MOTOR_B_PWM, OUTPUT );
  pinMode( MOTOR_A_DIR, OUTPUT );
  pinMode( MOTOR_A_PWM, OUTPUT );
  digitalWrite( MOTOR_B_DIR, LOW );
  analogWrite( MOTOR_B_PWM, LOW );
  digitalWrite( MOTOR_A_DIR, LOW );
  analogWrite( MOTOR_A_PWM, LOW );
  data=0;
}
void loop() {
  while (Serial.available() ) {
    data=Serial.read(); 
    if (data=='1'){
      digitalWrite(MOTOR_B_DIR, HIGH);
      analogWrite(MOTOR_B_PWM, 100);
      digitalWrite(MOTOR_A_DIR, HIGH);
      analogWrite(MOTOR_A_PWM, 100);
      Serial.println("on");
      data = 0;
    }
    else {
    digitalWrite(MOTOR_B_DIR, LOW);
      digitalWrite(MOTOR_B_PWM, LOW);
      digitalWrite(MOTOR_A_DIR, LOW);
      digitalWrite(MOTOR_A_PWM, LOW);
      Serial.println("off");
      data = 0;
    
    }
    data=0;
  }
}

The problem is that I can't figure out how to write a program for arduino that my motors would be running as long as im pressing the button, the moment i am not pressing the button they would not move, so basically I need to clean up the data after every loop but that's not working

That is the wrong approach. The correct approach is to send one value, ONE TIME, when the "button" becomes pressed, and a different value when the switch becomes released.

manic9:
The problem is that I can't figure out how to write a program for arduino that my motors would be running as long as im pressing the button,

I presume you mean a button on your PC?

If so your PC code should send one character when the button goes down (keydown) and a different character when the button is released (keyup). For example you could use 'A' for key down and 'a' for key up.

When the Arduino receives the 'A' it starts the motor. When it receives the 'a' it stops the motor.

What software are you using on your PC ?

...R
(overlapped with @PaulS)