How do I stop an Arduino sketch?

I am able to use the Arduino sweep servo example sketch. I can't for the life of me figure out how to end the for loop causing the program to stop. Even if I close the Arduino IDE down it continues to run. If I unplug the usb cable and plug it back in it continues to run the sweep program even without the Arduino IDE app open? It seems some service or executable is still running. Can someone please tell me how to stop the program. Maybe even through the serial monitor interface??
I would even like to rewrite the program to just move the servo a couple of degrees and then stop/pause until I tell it to move further. Thanks in advance.

the arduino is its own little computer, it starts the sketch and continues to run whatever is in void loop() forever unless you specifically program it to do otherwise

"I would even like to rewrite the program to just move the servo a couple of degrees and then stop/pause until I tell it to move further. "
That's how you stop it - let it do an action after it sees a button push, then it goes back to reading the pin/port ready to act on another button push.
Or reading a serial port. Or taking analog samples.

Could you direct me to a sketch that doesn't use a loop but rather moved the servo to a specified degree? I am unable to find any such code. Or can you tell me how to modify the example sweep code to stop the loop. I am remoting into my pc from work and controlling a webcam attached to the top of the servo from across the net. This is why I don't want it to continually move.

This is why I don't want it to continually move.

Good idea.

Could you direct me to a sketch that doesn't use a loop but rather moved the servo to a specified degree? I am unable to find any such code.

This implies that you haven't bothered to try to understand the sketch that you have. If you don't want something to happen in a loop, don't put the action inside a loop. I'm pretty sure that with a little study (and I do mean a little) you'll be able to distinguish the loop part and the action part. Then, remove the one you don't want.

I do understand the premise behind loops. I just can't find code anywhere on the net that would allow me make the servo move to a specified degree then stop so it can easily be controlled over the net through remogte access. Is the Arduino code Java or C+? I was also under the impression that I could type code in the serial monitor to make the servo move accordingly. Sorry for the newbie questions. If there were a primer I could reference I would be more than happy to look at it.

welchsc:
I just can't find code anywhere on the net that would allow me make the servo move to a specified degree then stop so it can easily be controlled over the net through remogte access.

With such a specific requirement, it's no surprise that the exact code you're looking for isn't readily available.

Is the Arduino code Java or C+?

Neither, it's C++.

I was also under the impression that I could type code in the serial monitor to make the servo move accordingly.

Not sure what gave you that impression, the sweep example has no Serial communications code in it, what-so-ever.

If there were a primer I could reference I would be more than happy to look at it.

There are dozens of example sketches you can look at that already come with the Arduino IDE.

you can do what you want in the "Setup" if you want to do it only once.

Take a look at the
Examples:Servo:Knob code in the IDE:

// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
}

This reads a potentiometer, and moves the servo based on the reading.
Do the same but get the reading from your remote connection instead.

void loop(){
// check outside source, see if new position came in
if (new position came in && new position is within allowed limits){
// move the servo - say 5 degrees left or 5 degrees right depending on the command  - all depends on the protocol you set up.
}
else {
// do not move servo
}
} // end loop