problem with delay

hi
im trying to apply delay on assigning stop function on code but program doesnt stop for assigned value its just acting weird, maybe im not doing somthing right, anyone can help with this code?

#include <AccelStepper.h>


AccelStepper stepper1(1, 3, 2);


#define  LEFT_PIN  8
#define  STOP_PIN  12
int  SPEED_PIN =A0;
int  POMAK_PIN =A1;
int  DELAY_PIN =A2;
#define  MAX_SPEED 5000
#define  MIN_SPEED 0.1
#define  MIN_POMAK 0
#define  MAX_POMAK 10000
void setup() {
  pinMode(SPEED_PIN,INPUT);
  pinMode(POMAK_PIN,INPUT);
  pinMode(DELAY_PIN,INPUT);
  stepper1.setMaxSpeed(10000);
  pinMode(13,OUTPUT);
  digitalWrite(13,HIGH);
  pinMode(LEFT_PIN, INPUT_PULLUP);
  pinMode(STOP_PIN, INPUT_PULLUP);
  
}

void loop() {
  static int kasnjenje = 0;
  kasnjenje = analogRead(DELAY_PIN);
  kasnjenje = map(kasnjenje, 0, 1023, 0, 10000);
  
  static float current_speed = 0.0;
  static int analog_read_counter = 1000;

  static char sign = 0;
  static int analog_value = 0;



  if (digitalRead(LEFT_PIN) == 0) {
    delay(kasnjenje);
    sign = 1;
  }
  
  else if (digitalRead(STOP_PIN) == 0) {
    delay(2000);
    sign = 0;
    }
  
  

  if (analog_read_counter > 0) {
    analog_read_counter--;
  }
  else {
    analog_read_counter = 3000;

    analog_value = analogRead(SPEED_PIN);

    stepper1.runSpeed();

    current_speed = sign * ((analog_value / 1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;

    stepper1.setSpeed(current_speed);
  }


  stepper1.runSpeed();
}

Maybe I don't understand your question, but delay() function is not to stop the program.

luisilva:
Maybe I don't understand your question, but delay() function is not to stop the program.

yea i know i need to put delay before program assign 0. on speed or i need to delay before motor stop...