i want to know how to stop movement of servo motor at current position when for

i want to know how to stop movement of servo motor at current position when for some value of ultrasonic sensor??? any one can help me ?

Please post some example code showing the problem.

any one can help me ?

I can't even understand you.

Nor does the code you posted help make things clearer.

i am using servo and ultrasonic sensor hc sr04 i want to know how to stop movement of servo motor at position where sensor detect at specified distance with some condition greater than or less than that distances if distance is greater than spasific value motor continue to move but when distance is less than that value i want to stop motor at its current position
i want to modify this code

// Includes the Servo library
#include <Servo.h>.
// Defines Tirg and Echo pins of the Ultrasonic Sensor
const int trigPin = 10;
const int echoPin = 13;
// Variables for the duration and the distance
long duration;
int distance;
Servo myServo; // Creates a servo object for controlling the servo motor
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600);
myServo.attach(8); // Defines on which pin is the servo motor attached
}
void loop() {
// rotates the servo motor from 15 to 165 degrees
for(int i=15;i<=165;i++){
myServo.write(i);
delay(30);
distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree

Serial.print(i); // Sends the current degree into the Serial Port
Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
Serial.print(distance); // Sends the distance value into the Serial Port
Serial.print("."); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
}
// Repeats the previous lines from 165 to 15 degrees
for(int i=165;i>15;i–){
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
}
// Function for calculating the distance measured by the Ultrasonic sensor
int calculateDistance(){

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance= duration*0.034/2;
return distance;
}

Why have you started a second thread on this subject ?

Why did you start a new thread?

You realize, I hope, that loop() is called over and over. Stopping the servo movement, caused by one for loop, when some distance reading is found is easy. Just use break;. Stopping the other for loop from scanning in the other direction is more challenging (a 1.05 on a scale of 1 to 10, compared to 1.01 for a break statement).

Stopping the movement for multiple iterations of loop() is more challenging (a 1.1). Exactly what are you trying to accomplish with waving the servo around? Exactly why do you want to stop moving the servo? Under what circumstances do you want to start moving the servo again? Having specific requirements makes writing code so much easier.