Servo coding

I have a code that when I push a button my servo starts to sweep 0-180 then back 180-0. That part works good, my problem is that I am displaying the degree of 0-180 on an LCD display and as soon as I push the button the display does it’s count 0-180 whether or not the servo is actually still moving. I am trying to get it to freeze at whatever value the servo is at the time I release the button. So I think what I need is a way to interupt the code as soon as the servo is stopped but unsure on how to accomplish that.

#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
int pos = 0;    // variable to store the servo position   
int pin = 3;
#include <LiquidCrystal.h>
LiquidCrystal lcd(10, 11, 7, 6, 5, 4);

void setup() 
{ 
  pinMode(pin, INPUT);
  lcd.begin(16, 2);
  Serial.begin(9600);
  myservo.attach(2);  // attaches the servo on pin 9 to the servo object 
} 

void loop() 
{{
if (digitalRead(3) == LOW)
   myservo.write(pos);
   delay(15);
   Serial.println("Current Angle"); 
   Serial.print(pos); 
   lcd.print(pos);
   delay(100);
   lcd.clear();}
{ if (digitalRead(3) == HIGH)
{ for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  { myservo.write(pos);              
    delay(15);   
    Serial.println("Current Angle");
    Serial.print(pos); 
    lcd.print(pos);
    delay(100);
   lcd.clear();} 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  { myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);
   Serial.println("Current Angle"); 
   Serial.print(pos); 
 lcd.print(pos);
 delay(100);
 lcd.clear();}} 
}}

Look at your first “if”.
Is there a brace after it?
Should there be?

It's a lot easier, in my opinion, to see the structure of your code if you put each and every { and } on its own line and use Tools + Auto format to properly indent the code.

You can easily see useless curly braces (you have several) and missing braces.

{
   if (digitalRead(3) == LOW)
      myservo.write(pos);
   delay(15);
   Serial.println("Current Angle"); 
   Serial.print(pos); 
   lcd.print(pos);
   delay(100);
   lcd.clear();
}

clearly doesn't look like I think you expect it to look.

So I think what I need is a way to interupt the code as soon as the servo is stopped

What you probably need is not an interrupt, but a "while" loop.

Your use of '{' and '}' is absolutely hideous and makes faults in the structure of your code almost inevitable.

Follow the advice that PaulS gave to lay out and indent your code properly so that the control structure is apparent. I think you will probably find it very obvious what you're doing wrong then.

Yeah I realize that now, ive been trying to follow Paul's advice, appreciate the help. I didn't realize how important the organization for these codes was, I just started doing this as a class for school, and I must admit that mine was very ugly. Hopefully now I'll be able to figure it out