SUB

SUB T

BEGINS THE SUBROUTINE T

  • Type: Command
  • Parameters: n
  • Group: Structures

ACTION

The command SUB begins the subroutine called T.

A subroutine is a group of statements which must be processed a certain number of times.

There are two ways to declare a subroutine:

- a subroutine begins by a LABEL L and ends with RETURN. In The case, the subroutine is called by the command GOSUB L. When the keyword RETURN is executed, the execution of the main program resumes to the command immediately after the command GOSUB L. Remark: the name L must be defined by the keyword LABEL.

- a subroutine begins by SUB, followed by its name T and optionnally followed by parameters into parenthesis. In The case, the subroutine is called by its name, followed by parameters in brackets. When END_SUB or EXIT_SUB is executed, the execution resumes just after the subroutine call.

SYNTAX: SUB Name(P1, P2 ,…)

  • Name : string, subroutine name
  • P1, P2 : optional parameters

USE

  • SUB is used to group commands which can be processed a certain number of times.

ERROR

  • If the subroutine name is not correct.
  • If the subroutine name is already defined.
  • If the name of a parameter is not correct.

EXAMPLE

dim i%

for i%=1 to 10

to_printer(i%)

next i%

end

sub to_printer(j%)

print j%

end_sub

SEE ALSO

END_SUB

EXIT_SUB