State machinese for serial input I am trying to control a servo using keyboard.

void loop() {
if (Serial.available() &gt; 0) {
  x = Serial.parseInt();
  while(pos &lt; 180){
  pos = x + pos;
  Serial.println(pos);
  myservo.write(pos);
  delay(100);
 }
  }
else if(Serial.available() &gt; 0){
if(pos&gt;=180){
  pos = 0;
  delay(500);
  myservo.write(0);

  }
  }
 }


Right now the servo takes the input correctly. The only thing is that it wont change positions immediately. It will wait until it hits 180 resets to 0 and then use the input I put in. This isnt the behaviour I want. I want it to change immediately. How Do I set this up?
I don't understand why you use 2 Serial.available condition.
I try to rewrote your program based on my imagination, so do not hate me if its wrong.
Why don't you try this and tell the results:    

int pos = 0,x=0;
void loop() 
{
  while (Serial.available() &gt; 0) x = Serial.parseInt();

  pos+=x;
  if (pos&gt;180) pos = 0;
  myservo.write(pos);
  Serial.println (pos);
  delay(100);
}