To routine name [:parameter names]

If you want to split up your code or call a similar set of commands at various times, it is a good idea to create routines.

The "To" command allows you to set up your routine. It is as if you are saying "to do this ..."

You need to give your routine a name to describe it so that you can call it and the commands contained within it are only called when the name of the routine is reached. You also need to finish your routine using the command END.

It is perhaps best described with an example.

Example:

TO TRIANGLE :SIZE
REPEAT 3
[
FD :SIZE
RT 120
]
END

TRIANGLE 50


In the example, a routine called TRIANGLE is created that has one parameter it expects - the "SIZE" parameter. This is used within the routine by the forward command.

The last line in the example shows how the routine is called and in this example it passes in the value of 50.