Commanding a servo

Can someone explain this code for me ? i'll be grateful!

#include "Servo.h"

Servo myservo;
int pos = 0;

void setup()
{
myservo.attach(9);
}

void loop()
{
for(pos = 10; pos < 150; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 150; pos>=10; pos-=1)
{
myservo.write(pos);
delay(15);
}
}

It's a basic servo sweep program.

Please remember to use code tags when posting code

Here's the example code that comes included with the servo library. It's identical to your code, except it has some helpful comments.

Maybe the comments will provide the explanation you need.

Here you are.

Note that I put the code in code tags to make it easier to copy to an editor and to avoid the forum software misinterpreting certain commands as HTML tags

#include "Servo.h"  //make the Servo functions available to the program

Servo myservo;  //create a Servo object named servo
int pos = 0;  //declare the variable pos and set its value to 0

void setup()
{
  myservo.attach(9);  //tell the program to control the servo object using pin 9
}

void loop()
{
  for (pos = 10; pos < 150; pos += 1) //make the value of pos vary from 10 to 149 in steps of 1
  {
    myservo.write(pos); //move the servo to the angle held in the pos variable
    delay(15);  //do nothing for 15 milliseconds
  }
  
  for (pos = 150; pos >= 10; pos -= 1)  //as above but in reverse direction 150 to 10
  {
    myservo.write(pos);
    delay(15);
  }
} //go back and do it all over again