How can the loop be stopped after one cycle?

Start with the servo examples, those will show you how to basically control a servo (I assumed you got that part already). Get your servo to move left and right, do a slow sweep, etc.

Then you know how to create the servo object, and what my code example actually does. It's meant to be an example to show you the principle, not meant to be a fully functional and ready-to-compile sketch.