Available on: all targets

PROCEDURE...END PROC

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.

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.

SYNTAX

 PROCEDURE name[ par1[, par2[, ... ]]] ]
  ...
 END PROC[ expression ]


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 PROCEDURE test[ a, b ]
    DEBUG "HELLO WORLD! "; (a+b)
 END PROC
 PROCEDURE sumOf( x, y )
 END PROC[x+y]
 PROCEDURE hundred
 END PROC[100]


Used in:

ABBREVIATION: Prcd...EePrb

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

PROCEDURE...END PROC ↔ Prcd...EePrb

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS