I'm a student new to Arduino, and I'm trying to control a servo motor by using write command. However, when I run the code, it just keep rotating clockwise for a small angle at a time, and the time interval does not follow the delay too.
You may need to allow more time for the servo to move. A data sheet that I found has the motion versus time specification. Note that the times are usually unloaded times. A servo with a load will be slower, depending on load.
It takes time for the servo to start, move to the commanded position and stop. Look at the data sheet under speed:
Speed: 4.8V: 0.33 sec/60° 6.0V: 0.27 sec/60°
with a 4.8V power supply it takes 330ms to move 60° under no load, so to move 90° it would take 495ms (under no load).
How is your servo powered? If it is powered by the Arduino, that can cause problems, too. The Arduino is not a power supply. Power the servo with an external supply like a pack of 4 AA batteries.