arduino + l293d shield + joystick

I use a stepper from a CD-ROM with arduino + l293d shield + joystick.My code works fine until the next day when after connecting arduino to the motor, it moves forward forever. So, it works one day and on another one, won't. Here is my code:

#include <Stepper.h>
#include "AFMotor.h"
#define joystick A0
int buttonState;
int sensorReading = 0;
int stepRev = 5;
  const int stepsPerRevolution = 20;  
    const int motorSpeed = 255; 
        const int motorSpeed2 = 255;   
//  Stepper myStepper(stepsPerRevolution, 5,6);   
AF_Stepper Stepper1(20,2); 
 
   
void setup() {
   Serial.begin(9600);
   sensorReading = analogRead(joystick);  
}
void loop() {
Stepper1.release();
sensorReading = analogRead(joystick); 
  
if (sensorReading<500){ 

delay(10);
Stepper1.setSpeed(255); 
Stepper1.step(stepRev,FORWARD,MICROSTEP);
delay(10);
Stepper1.release();
sensorReading = analogRead(joystick);   
  Serial.print("tick");
}
if (sensorReading >600){
delay(10);
Stepper1.setSpeed(100); 
Stepper1.step(stepRev,BACKWARD,MICROSTEP);
delay(10);
Stepper1.release();
sensorReading = analogRead(joystick);  
  }
 
}

When I remove the first "if", it is fine, but with two "if", it is looped to move forward.

Well, if your analogRead() continuously reports a value below 500, your motor will continue to move forward.

How about you print the value you read and see?