Servomotor programming issue

I am having trouble with a program for a project. The idea is that if the voltage into an analogue pin is less than about 2.5V then the servomotor will move 1 increment to the right, delay and then check again and if the voltage is still less than 2.5V, the motor will again move another increment. The opposite if voltage is greater than about 2.5V. I have tried multiple programs and I get movement only once.

#include <Servo.h>

Servo myservo;
const int buttonPin = 2;

int voltin = 1;
int val;
int pos = 0;



void setup() {
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object

}

void loop() {
val = analogRead(voltin); if (val > 520) {            
     myservo.write(pos + 1);                  
 delay(15);                           
}
else { myservo.write(pos - 1);
delay(15);
} delay(15);


}

You're not assigning a new value to the variable "pos".

Please use code tags when posting code.

#include <Servo.h>

Servo myservo;

const int VoltInPin = A1;
int Position = 90;

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  int val = analogRead(VoltInPin);
  if (val > 520) {
    if (Position < 180)
      Position++;
  }
  else {
    if (Position > 0)
      Position--;
  }
  myservo.write(Position);
  delay(15);
}