Execute loop for an assigned time frame

By using the function millis()

storing a stimestamp = a snapshot of time right before your while-loop starts executing
and then storing a second timestamp right after your while-loop
then calculating the difference.

most stripped down demo-code to demontrate this

unsigned long myCounter = 0;
unsigned long startTime;
unsigned long endTime;


void setup() {
  Serial.begin(115200);
  Serial.println("Setup-Start");
}


void loop() {

  startTime = millis();
  
  while (myCounter < 10000000) {
    myCounter++;
  }
  
  endTime = millis();
  
  Serial.print("counting up to 10.000.000 took ");
  Serial.print(endTime - startTime);
  Serial.println(" milliseconds");
  myCounter = 0;
}

serial monitor

counting up to 10.000.000 took 875 milliseconds

I assume that your final code will do much more than just moving motor 1 and that you want these other things to execute at the same time as motor 1 is moving.

This requires non-blocking coding
Your while-loop is blocking.
As long as the while-loop is running you can't do anything else.
Only exception code that you put into the while-loop
but this would mess up the code.

the one and only loop of non-blocking code is
void loop() itself

I started a tutorial about this which is yet not finished

best regards Stefan