You write a subroutine definition to specify what a subroutine actually does. A subroutine definition consists of information regarding the subroutine’s name, names of parameters, extra subroutine modifiers, and the body of the subroutine. The subroutine body is a series of statements enclosed in braces, similar to a block.
Here is the general form of a subroutine definition:
sub subroutine-name pre-modifiers (parameter-list) modifiers
{
subroutine-body
}
Here is an example of a simple subroutine, which simply increases the sub AddX (amount) {
x += amount
}
Unlike in C, subroutines cannot return values. If you wish to store the result of a subroutine, you will have to make the subroutine write said result into some field, at least temporarily, so it can be later retrieved if needed:
sub GetSquare(number) {
misc = number * number
}
Here, the result of the power of 2 of ...
GetSquare(3)
var the_square = misc
...