Limit switch with Nema 17 and A4988

const int dirPin1 = 5;
const int stepPin1 = 4;
const int dirPin2 = 7;
const int stepPin2 = 6;
const int lmswitch = 2;
const int spr = 10000;


void setup()
{
  // Declare pins as Outputs
  Serial.begin(9600);
  pinMode(stepPin1, OUTPUT);
  pinMode(dirPin1, OUTPUT);
  pinMode(stepPin2, OUTPUT);
  pinMode(dirPin2, OUTPUT);
  pinMode(lmswitch , INPUT);
  digitalWrite(dirPin1, HIGH);

}
void loop()
{
  if (digitalRead(lmswitch) != LOW){
  StepRight();
  StepLeft();
  }

}

void StepRight()
{
  while (digitalRead(lmswitch) != LOW)     
  {
    digitalWrite(dirPin1, HIGH); //pin 8, CW

    for (int x = 1; x < 10000; x++)     
    {
      digitalWrite(stepPin1, HIGH);        
      delayMicroseconds(2000);     
      digitalWrite(stepPin1, LOW);         
      delayMicroseconds(2000);     
    }
  }
}

void StepLeft()
{
  while (digitalRead(lmswitch) != LOW)   
  {
    digitalWrite(dirPin1, LOW); 

    for (int x = 1; x < 10000; x++)     
    {
      digitalWrite(stepPin1, HIGH);       
      delayMicroseconds(2000);     
      digitalWrite(stepPin1, LOW);         
      delayMicroseconds(2000);    
    }
  }
}

it still not working , it always run never change direction when i push to limit switch