I'm trying to Interrupt with a switch. Can I do this?

I wrote this on my phone, so it is completely uncompiled or tested, but replaces the delays in the sweep example:

#include <Servo.h> 
Servo myservo; 

const int upperLimit = 180;
const int lowerLimit = 0;
int pos;
bool rampUp = true

unsigned long lastTime;  
unsigned long moveInterval = 15;

void setup() 
{ 
  myservo.write (pos);
  myservo.attach(9); 
} 
 
void loop ()
{
  unsigned long timeNow = millis ();
  if (timeNow - lastTime > moveInterval) {
    lastTime = timeNow;
    if (rampUp) {
      pos++;
      if (pos >= upperLimit) {
        rampUp = false;
      }
    } else {
      pos--;
      if (pos <= lowerLimit) {
        rampUp = true;
      }
    }
    myservo.write (pos);
  }
}