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 name CALL name parameters "[" [par1 [, par2[, ...]]] "]"
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:
CALL ↔ Ca
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