combining programs?

This:

  for(int x=40; x<=140; x++){
    servo1.write(x);
    //delay (10);
   millis() = previousTime;
    }

will simply do 100 "servo.write"s and 100 assignments to "millis()" (which is a function and therefore and illegal lvalue) without stopping.
It isn't surprising it sweeps from one end of the travel to the other.
You can't use a "for" loop for this sort of "blink-without-delay" application, you need to code the loop explicitly, kind-of turning it inside-out.