Read about loops in C and read the API thread on the script writing board. For what you want you really only need 1 'for' loop. Look at the sample scripts.
/*
@title Focus stack
*/
wait_pic(); //wait for you to press the shutter to start
for (int i = 0; i < 10; i++) //repeat the stuff in brackets below 10 times
{
focus(1); //moves focus 1 step. can also be a negative
takepic(); //takes a pic duh
//sleep(.5); //wait .5s before starting the loop over
}
You would have to be in Liveview with autofocus enabled to use this.
There is also
focus_setup(int stepsize, int delay, int wait); // see Focus -> Focus Settings menu
to set all those specific settings in the script if you like. You would call it by adding focus_setup(1,2,3); for example, before the loop.
You might have a problem with the script trying to run faster than the camera can take the pics and move focus. If that is the case and you are missing shots then remove the // in front of the '//sleep...' to give it some more time to clear buffer and move focus.
Scripts are not going to really speed up the picture taking part of the process, just maybe the setup.