Hi again, ok I have develop this code:
I can't make sense of that code - it is nothing like what I would expect to solve your problem.
I suggest you write a bit of code designed to be run at regular intervals, which checks the switch state and sets the motor speed accordingly. The code would need to:
Test whether the switch input was high or low.
If low, stop the motor.
Otherwise, check whether the motor was at the desired target speed and alter the speed if necessary.
This would be an ideal candidate to be implemented as a function. You will need to arrange for this function to be called at regular intervals. You could just call delay() to make your sketch stop after each call, but it would be better to use the technique demonstrated in Blink Without Delay to call it at regular intervals - this would leave your sketch free to do other things independently.