Servo will not go to set angle

This is my first time working with servos so I dont know if I'm doing something wrong. I want to set the servo to a specific angle, like 90 or 0. But it just doesn't do anything.
I copied and pasted the servo sweep code from the Arduino website and it works fine:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

However, if I simply want to set the arduino to a certain angle, it does not work:

#include <Servo.h>

Servo myservo;  
int pos = 0;    

void setup() {
  myservo.attach(9);  
  myservo.write(90);
}
void loop() {
}

It doesnt matter what angle I input, it does not change. Can anyone see a problem? It is a problem with the servo?
Thanks for any help!

The non-working program does not have a loop() function. That is essential, even if it is empty - for example

void loop() {
}

...R

It does, but I didnt include it in that example, so it isnt the problem. I'll edit it now.

One problem may be that you just can't see any movement because 90 is the default that the servo normally goes to when attached. Try adding a couple of different moves to make sure. E.g.

void setup() {
  myservo.attach(9);  
  myservo.write(0);
  delay(500);
  myservo.write(90);
  delay(500);
  myservo.write(45);
}

Steve

sparpo:
It does, but I didnt include it in that example, so it isnt the problem. I'll edit it now.

Always post a complete program.

if you re-load the servo sweep program does it work?

...R

slipstick:
One problem may be that you just can't see any movement because 90 is the default that the servo normally goes to when attached.

That was my initial thought too, but right under the code OP said:

sparpo:
It doesnt matter what angle I input, it does not change.

If you are trying to power the servo from the Arduino 5V output, stop right now.

Use a 4xAA battery pack to power the servo, and connect the grounds.