This is the OP's original code with a bit of tidying up.
#include <Servo.h>
Servo myservo;
int leftPin = 8;
int servoPin = 13;
int pos = 90; // servo initial position
int delayPeriod = 3;
void setup() {
myservo.attach (13);
pinMode(leftPin, INPUT);
pinMode(servoPin, OUTPUT);
}
void loop() {
if(digitalRead(leftPin) == HIGH) {
if( pos > 0) {
pos = pos - 1;
}
myservo.write(pos);
delay(delayPeriod);
if ((pos == 0) || (pos < 0) {
pos = 180;
delay(5); // control speed to restart position
}
}
}
And this is a substantially modified version that (I think) does what the OP wants. It seemed like an opportunity to illustrate how to compartmentalize the code into different functions - each with a single purpose - even if it may be overkill for this short project.
Note that I have changed the switch pin to INPUT_PULLUP so the other side of the switch needs to be connected to ground.
#include <Servo.h>
Servo myservo;
byte leftPin = 8;
byte servoPin = 13;
byte switchValue = LOW;
int servoStep = 1; // int because we need negative values
byte pos = 90; // servo initial position
byte delayPeriod = 20;
void setup() {
myservo.attach (13);
pinMode(leftPin, INPUT_PULLUP);
pinMode(servoPin, OUTPUT);
}
void loop() {
readSwitch();
updatePosition();
moveServo();
}
void readSwitch() {
if(digitalRead(leftPin) == LOW) { // unpressed button will be HIGH
switchValue = HIGH;
}
else {
switchValue = LOW;
}
}
void updatePosition() {
if (switchValue == HIGH) {
pos = pos + servoStep;
}
if( pos < 20) { // some servos can't go all the way from 0 to 180
// adjust to suit your servo
pos = 20;
servoStep = 1;
}
if( pos > 160) {
pos = 160;
servoStep = -1;
}
}
void moveServo() {
myservo.write(pos);
delay(delayPeriod);
}
...R