Finish task in if loop

I am reading a PIR motion sensor. If motion is detected (HIGH), motor is run for a determined distance. Problem is, if motion is not detected (LOW), the motor stops before it reach its distance. Is it possible to let a task finish in if loop regardless of the sensor input changing its logic (to LOW)?

Without seeing your code its difficult to understand what you mean.

I assume you're using an If statement that's using the PIR input as the condition. You could use the PIR input to set a variable (PIRvar) that sets the motor to turn the determined distance. And use the IF statement to stop the motor after the determined distance by turning off the PIRvar variable.

if(PIR input == HIGH){
bool PIRvar=HIGH;
}
if(PIRvar==HIGH){
turn motor determined distance..
PIRvar=LOW;
}

Is it possible to let a task finish in if loop

There is no such thing as an "if loop".

Post your code