CALL name CALL name parameters "[" [par1 [, par2[, ...]]] "]"
The CALL
command is used to call a previously defined procedure
(or subroutine) within the same program. A procedure is a separate
block of code designed to perform a specific task. By using CALL
,
you can execute the code within the procedure multiple times, without
having to rewrite the same statements each time.
Before you can call a procedure, you must define it. In ugBASIC, a
procedure is typically defined with the PROCEDURE
keyword followed
by the name of the procedure. Inside the procedure, you write
the statements that should be executed when the procedure is called.
To execute the code within the procedure, you use the CALL
command
followed by the name of the procedure.
When the program reaches this line, control is transferred to the
first statement in the procedure. Once all the statements in the procedure
are executed, control returns to the line after CALL
.
Dividing a program into procedures makes the code more organized and easier to read, and a procedure can be called multiple times from different parts of the program, avoiding code duplication. Procedures can be used to break a complex problem into simpler subproblems, that helps to create a hierarchical structure in the program.
You can also pass arguments to a procedure, enclosed in square parameters: arguments are values that are passed to the procedure when it is called and that can be used within the procedure itself. If the procedure returns a value, the calling statement just ignore it.
By breaking code into procedures, it becomes easier to understand and maintain, and by reusing the same procedures in multiple parts of the program, you reduce the chances of introducing errors. Finally, if you need to change one part of the code, you can simply change the corresponding procedure, without having to make changes in all the parts of the program that use that part of the code.
Important: if the OPTION CALL AS GOTO
pragma is in effect, the instruction
will be considered as a GOTO
rather than a GOSUB
. So, no return value and
no return, at all. This not applies to system calls.
CALL factorial[42]
See also the following example files:
Ca
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!