PROCEDURE name[ par1[, par2[, ... ]]] ] ... END PROC[ expression ]
This couple of keywords create a procedure by giving it a name. The name is
then followed by a list of parameters and the procedure must be ended
with an END PROC
command. PROCEDURE
and END PROC
commands
should be placed on their own individual lines, but it is not mandatory.
Following the convention in other BASICs of the time, such as Simon's BASIC or Tuned Simon's BASIC, the procedure name can also contain spaces. In this case, the trailing space will not be considered as part of the name.
It is possible to place the procedure definition anywhere in the program.
When ugBASIC encounters a procedure statement, the procedure is recognised
and a jump is made to the final END PROC
. In this way, there is no
risk of executing your procedure by accident.
Following the procedure's name can be given a list of parameters. This creates a group of local variables that can be loaded directly from the main program. Note that the values to be loaded into parameters must be entered between square brackets as part of the procedure call. This system works equally well with constants as well as variables, but although you are allowed to transfer integer, real or string variables, you may transfer also arrays using this method. If you need to enter more than one parameter, the variables must be separated by commas.
As an option, you can specify a value for the function to return.
The value must be indicated in square brackets ([…]
).
The value will then be copied into the PARAM
variable and
returned by the call, if the call was made in the context of an expression.
Important: if the OPTION CALL AS GOTO
pragma is in effect, the instruction
will be considered as a NOP
.
PROCEDURE test[ a, b ] PRINT "HELLO WORLD! "; (a+b) END PROC PROCEDURE sumOf( x, y ) END PROC[x+y] PROCEDURE hundred END PROC[100]
See also the following example files:
PrcdEePrb
If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!