Stopping stepper motor if infrared sensor detects something

Hey, I am having trouble with something. I need a stepper that continuously spins until the something passes the infrared sensor. I cant seem to figure out how to go about this. In the methods I have tried, the infrared only checks for the object to pass for an instant then goes about the loop and then does the same again and again. If something passes in the time where the stepper is spinning, the infrared does not detect anything and nothing stops.

while(value < 15 ){
        digitalWrite(IR_LED_PIN, LOW);
        delay(5);   
        ambient = analogRead(IR_INPUT_PIN);
        
        digitalWrite(IR_LED_PIN, HIGH);
        delay(5);
        lit = analogRead(IR_INPUT_PIN);
        
        value = lit - ambient;
      Serial.println(value);
      
      
      stepper.moveTo(2600);
       while (stepper.currentPosition() != 2400){ // Full speed up to 300
         if(value > 15)
        break;
         stepper.run();
       }
       stepper.stop(); // Stop as fast as possible: sets new target
       stepper.runToPosition(); 
    
      stepper.moveTo(-1600);
      while (stepper.currentPosition() != 0){ // Full speed basck to 0
        if(value > 15)
        break;
        stepper.run();
      }
      stepper.stop(); // Stop as fast as possible: sets new target
      stepper.runToPosition(); 
    }
    coinsChange = 0;
   }

Basically, I want it so that if the sensor detects anything over the number of 15 during ANY time of the loop it will stop the whole thing

In a while loop, move the stepper one step at a time. After each step check the IR. If nothing detected, go round the loop again. If something detected, jump out of the loop so that the motor stops. Keep the loop short so as not to slow the motor too much.