{{htmlmetatags>metatag-robots=() metatag-title=(CALL | ugBASIC User Manual) metatag-keywords=(ugBASIC,Commodore 64,Commodore PLUS/4,ZX Spectrum) metatag-description=(Manual page for CALL) metatag-media-og:image=(:ugbasic:logo-ugbasic-fb.png) metatag-og:title=(CALL | ugBASIC User Manual) metatag-og:description=(Manual page for CALL) }} ====== ugBASIC User Manual ====== ===== CALL ✓ ===== ===== SYNTAX ===== CALL name CALL name parameters "[" [par1 [, par2[, ...]]] "]" ==== PURPOSE ==== 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. ==== EXAMPLE ==== CALL factorial[42] See also the following example files: * ''[[https://github.com/spotlessmind1975/ugbasic/tree/main/examples/procedures_param_01.bas|procedures_param_01.bas]]'' * ''[[https://github.com/spotlessmind1975/ugbasic/tree/main/examples/procedures_param_02.bas|procedures_param_02.bas]]'' ==== ABBREVIATION ==== Ca ==== AVAILABLE ON ==== * * Atari (400/800) * Atari XL/XE * Commodore 128 (MOS 8502) * Commodore 128 (Zilog Z80) * Commodore 64 * Commodore 64+REU * 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 [[https://github.com/spotlessmind1975/ugbasic/issues/new?title=ISSUE ON CALL|open an issue]] for this keyword on GitHub. Thank you!===== POWERED BY ===== [[:ugbasic:user:index|{{ :ugbasic:user:logo-ugbasic.png?nolink&600 |}}]]