Interrupting a servo sweep with a force sensor
I've written this code without access to a compiler, 
so there might be errors. Use it as an idea how to solve the quest. Hopefully the comments are helpful. Don't hesitate to ask if you do not understand or correct me if you see an error. 

#include &lt;Servo.h&gt;

Servo myservo;

// end positions of the servo    
// declared as constant values
const int minPos = 10; 
const int maxPos = 180; 

int servoAngle;

int force;
char code;

void setup() 
{
  Serial.begin(9600);

  myservo.attach(4);
  // move the servo to minPos
  // or whatever you want/need
  servoAngle = minPos;
  myservo.write( servoAngle ); 

  // PPK: keep code as simple as possible -&gt; sweep removed

  // PPK: removed - this makes no sense here
  // code = Serial.read(); 
}

void loop() 
{
  // PPK: here you check if data is available (I added "&gt; 0")
  if( Serial.available() &gt; 0 )
  {
    // PPK: but you did not read the data
    // Let's do it
    char newCode = Serial.read(); 
    If ( newCode == '0' || newCode == '1' )
    {
      // only "0" and "1" are valid codes
      code = newCode;
    }
  }

  if ( code == '0' &amp;&amp; servoAngle &gt; minPos )      
  {
    servoAngle--;
    myservo.write( servoAngle );
  }
  else if ( code == '1' &amp;&amp; servoAngle &lt; maxPos )
  {
    force = analogRead( A1 );
    Serial.println( force );
    if ( force &gt; 300 )
    {
      servoAngle--;

      // PPK: the next line is only necessary if you want the
      // servo to go towards the min position
      // if a force &gt; 300 is detected
      // remove the line if you wish to 
      // hold the servo at the position where 
      // the force exceeds 300
      code = '0':
    }
    else
    {
      servoAngle++;
    }
    myservo.write( servoAngle );
  }
  // a little delay to slow down the servo
  // remove it if you want
  delay( 10 );
}


EDIT

If you intend to stop the servo if force &gt; 300, you can add a flag that indicates the exceptional state.

#include &lt;Servo.h&gt;

Servo myservo;

const int minPos = 10; 
const int maxPos = 180; 

int servoAngle;

int force;
char code;
int flagServoStopped = 0;

void setup() 
{
  Serial.begin(9600);

  myservo.attach(4);
  servoAngle = minPos;
  myservo.write( servoAngle ); 
}

void loop() 
{
  if( Serial.available() &gt; 0 )
  {
    char newCode = Serial.read(); 
    If ( newCode == '0' || newCode == '1' )
    {
      code = newCode;
    }
  }

  if ( flagServoStopped == 1 &amp;&amp; code == '1' )
  {
    // The servo is frozen as long as the stop flag is set and
    // you have not entered a '0'.
    // leave the loop
    return;
  }

  // in case `code = '0'`, reset the flag if it is set.
  flagServoStopped = 0;

  if ( code == '0' &amp;&amp; servoAngle &gt; minPos )      
  {
    servoAngle--;
    myservo.write( servoAngle );
  }
  else if ( code == '1' &amp;&amp; servoAngle &lt; maxPos )
  {
    force = analogRead( A1 );
    Serial.println( force );
    if ( force &gt; 300 )
    {
      flagServoStopped = 1;
    }
    else
    {
      servoAngle++;
      myservo.write( servoAngle );
    }
  }
  delay( 10 );
}