Nema stepper motor + microswitch endstop - Not interrupting movement.

Here Is the updated code,

When pressed End-stop 1 (on pin2) stops the motor at the end of its current rotation
End-stop 2 do connected to pin 3 does not.

I have also tested this using pin 4 instead, same issue

I still also have the issue where the end-stop press is not occurring immediately, and waiting for previous command to complete.

Thanks again!!!!

// Include the Arduino Stepper Library
#include <Stepper.h>

// Number of steps per output rotation
const int stepsPerRevolution = 200;


// Endstop
int Endstop = 2;
int Endstop2 = 3;

//Joystick

int x_key = A0;                                                                                   
int x_pos;



// Create Instance of Stepper library
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);



void setup()
{
  pinMode(Endstop, INPUT_PULLUP);
  pinMode(Endstop2, INPUT_PULLUP);

    
    // set the speed at 100 rpm:
  myStepper.setSpeed(100);
  // initialize the serial port for testing / logging:
  Serial.begin(9600);
}


//If the stepper motor is not hit (ie 1 all good, else 0 )

void loop() 
{

int Sensor = digitalRead(Endstop);
int Sensor2 = digitalRead(Endstop2);

x_pos = analogRead (x_key) ;  

  //print out the value of the pushbutton
  Serial.println(Sensor);
  Serial.println(Sensor2);
  Serial.println(x_pos);

// stop immediately if endstop hit

if ((Sensor == 0 ) or (Sensor2 == 0)) {

    myStepper.step(0);
  
                               }



// if the endstops are default (ie open default =1)

if ((Sensor == 1) or (Sensor2 == 1)){

// determine horizontal joystick input
                          
                                  if (x_pos > 600){
                                    
                                      Serial.println("clockwise");
                                      myStepper.step(stepsPerRevolution);
                             
                                   
                                                 }
                                                    
                                  if (x_pos < 450){
                                    
                                      Serial.println("Anticlockwise");
                                      myStepper.step(-stepsPerRevolution);
                 
                                    
                                                 }
                         
                              }
                                     




 
}