Smooth infrared signal?

So I’m programming a robot with an infrared receiver to be controlled from a tv remote, and I’m having the problem where I can either press a button and have the robot keep moving until another button press, or I can use a for loop with a timer to move it only while the button is pressed, but the result is that the movement is very jittery, pausing every 200 milliseconds (timer on the for loop). Is there any way to make it so that the motors turn on while a button is pressed, and off when it is not? I’m using this library:

And here is my code:

#include <AFMotor.h>
#include <IRremote.h>

AF_DCMotor motorR(3, MOTOR12_64KHZ);
AF_DCMotor motorL(4, MOTOR12_64KHZ);

int RECV_PIN = 2;
int motorSpeed = 255;

IRrecv irrecv(RECV_PIN);
decode_results results;


void setup()
{
  irrecv.enableIRIn();
}

void loop()
{
  if (irrecv.decode(&results)) 
  {
    long int decCode = results.value;
    switch (results.value) 
    {
    case 4064352766:
      drive();
      break;
    case 3028878891:
      reverse();
      break;
    case 3308754100:
      turnLeft();
      break;
    case 197779206:
      turnRight();
      break;
    default: 
      idle();
      break;
    }    
    irrecv.resume();
  }
}

void turnRight()
{
  motorR.setSpeed(motorSpeed);
  motorL.setSpeed(motorSpeed);

  unsigned long stTime = millis();
  unsigned long endTime = 1;
  for(unsigned long timeElapsed = 1; timeElapsed < 75; timeElapsed = (endTime - stTime))
  {
    motorR.run(BACKWARD);
    motorL.run(FORWARD);

    endTime = millis();
  }
  motorL.run(RELEASE);
  motorR.run(RELEASE);
}

void turnLeft()
{
  motorR.setSpeed(motorSpeed);
  motorL.setSpeed(motorSpeed);

  unsigned long stTime = millis();
  unsigned long endTime = 1;
  for(unsigned long timeElapsed = 1; timeElapsed < 100; timeElapsed = (endTime - stTime))
  {
    motorR.run(FORWARD);
    motorL.run(BACKWARD);

    endTime = millis();
  }
  motorL.run(RELEASE);
  motorR.run(RELEASE);
}

void drive()
{
  motorR.setSpeed(motorSpeed);
  motorL.setSpeed(motorSpeed);

  unsigned long stTime = millis();
  unsigned long endTime = 1;
  for(unsigned long timeElapsed = 1; timeElapsed < 200; timeElapsed = (endTime - stTime))
  {
    motorR.run(FORWARD);
    motorL.run(FORWARD);

    endTime = millis();
  }
  motorL.run(RELEASE);
  motorR.run(RELEASE);
}

void reverse()
{
  motorR.setSpeed(motorSpeed);
  motorL.setSpeed(motorSpeed);

  unsigned long stTime = millis();
  unsigned long endTime = 1;
  for(unsigned long timeElapsed = 1; timeElapsed < 200; timeElapsed = (endTime - stTime))
  {
    motorR.run(BACKWARD);
    motorL.run(BACKWARD);

    endTime = millis();
  }
  motorL.run(RELEASE);
  motorR.run(RELEASE);
}

void idle()
{
  motorR.run(RELEASE);
  motorL.run(RELEASE);
}

Never-mind AF, I figured it out. I removed all the for loops and such and replaced it to update “timer” to millis(), and then if there was no IR signal received, it would turn off the motors once “timer” was 50 milliseconds apart from the current millis(). Here’s my new code if anyone has the same problem in the future:

#include <AFMotor.h>
#include <IRremote.h>

AF_DCMotor motorR(3, MOTOR12_64KHZ);
AF_DCMotor motorL(4, MOTOR12_64KHZ);

int RECV_PIN = 2;
int motorSpeed = 150;

IRrecv irrecv(RECV_PIN);
decode_results results;

unsigned long timer;

void setup()
{
  irrecv.enableIRIn();
}

void loop()
{
  if (irrecv.decode(&results)) 
  {
    long int decCode = results.value;
    switch (results.value) 
    {
    case 4064352766:
      drive();
      break;
    case 3028878891:
      reverse();
      break;
    case 3308754100:
      turnLeft();
      break;
    case 197779206:
      turnRight();
      break;
    case 3379986294:
      motorSpeed = 150;
      break;
    case 3356842673:
      motorSpeed = 200;
      break;
    case 3063508398:
      motorSpeed = 255;
      break;
    default: 
      idle();
      break;
    }    
    irrecv.resume();
  }
  else
  {
    if((millis() - timer) > 50)
    {
      idle(); 
    }
  }
}

void turnRight()
{
  motorR.setSpeed(255);
  motorL.setSpeed(255);

  timer = millis();

  motorR.run(BACKWARD);
  motorL.run(FORWARD);

}

void turnLeft()
{
  motorR.setSpeed(255);
  motorL.setSpeed(255);

  timer = millis();

  motorR.run(FORWARD);
  motorL.run(BACKWARD);

}

void drive()
{
  motorR.setSpeed(motorSpeed);
  motorL.setSpeed(motorSpeed);

  timer = millis();

  motorR.run(FORWARD);
  motorL.run(FORWARD);

}

void reverse()
{
  motorR.setSpeed(motorSpeed);
  motorL.setSpeed(motorSpeed);

  timer = millis();

  motorR.run(BACKWARD);
  motorL.run(BACKWARD);
}

void idle()
{
  motorR.run(RELEASE);
  motorL.run(RELEASE);
}