User Tools

Site Tools


ugbasic:user:kw:procedure...end_proc
Translations of this page:


ugBASIC User Manual

PROCEDURE...END PROC ✓

SYNTAX

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

PURPOSE

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.

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]

See also the following example files:

ABBREVIATION

 Prcd...EePrb

AVAILABLE ON

  • Atari (400/800)
  • Atari XL/XE
  • Commodore 128 (MOS 8502)
  • Commodore 128 (Zilog Z80)
  • Commodore 64
  • TRS-80 Color Computer
  • TRS-80 Color Computer 3
  • ColecoVision
  • Amstrad CPC 664
  • Dragon 32
  • Dragon 64
  • Thomson MO5
  • Thomson MO5
  • Olivetti Prodest PC128
  • Commodore PLUS/4
  • SEGA SC-3000
  • SEGA SG-1000
  • VG-5000
  • Commodore VIC-20
  • ZX Spectrum 48

ANY PROBLEM?

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!

POWERED BY