Stepper motor speed control by encoder

Hi Robin, thanks for the reply.
Actually I did not tested the program yet, as I have my test bench my work only.
The blocking of Arduino in this case should not be an issue. I don't want to do anything else while running the stepper (this is actually a peristaltic pump). Only when encoder is turned, I like to change rpms of the stepper.
In general do you think that this approach will work? Mostly concerned about the variable "RPM" changing based on rotation of encoder?
thanks