RETURN: Difference between revisions
Jump to navigation
Jump to search
Code by Cyperium
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "'''RETURN''' is used in GOSUB procedures to return to the original call code line or a specified line label. {{PageSyntax}} :: '''RETURN''' [{''linelabel''|''linenumber''}] {{Parameters}} * RETURN without parameters returns to the code immediately following the original GOSUB call. * ''line number'' or ''linelabel'' after the RETURN statement returns code execution to that label. ''Usage:'' * Normally required at the end of a GOSUB procedure unless the...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
{{ | {{PageParameters}} | ||
* RETURN without parameters returns to the code immediately following the original [[GOSUB]] call. | * RETURN without parameters returns to the code immediately following the original [[GOSUB]] call. | ||
* ''line number'' or ''linelabel'' after the RETURN statement returns code execution to that label. | * ''line number'' or ''linelabel'' after the RETURN statement returns code execution to that label. | ||
Line 15: | Line 15: | ||
* RETURN is not used in error handling procedures. Error procedures use [[RESUME]] ''line number'' or [[RESUME|RESUME NEXT]]. | * RETURN is not used in error handling procedures. Error procedures use [[RESUME]] ''line number'' or [[RESUME|RESUME NEXT]]. | ||
* GOSUB procedures use line numbers or line labels designated with a colon after the number or label. | * GOSUB procedures use line numbers or line labels designated with a colon after the number or label. | ||
* If RETURN is encountered without a previous [[GOSUB]] call a [[ERROR Codes|"RETURN without GOSUB" error]] is produced. | * If RETURN is encountered without a previous [[GOSUB]] call a [[ERROR Codes|"RETURN without GOSUB" error]] is produced. | ||
* To avoid errors, place [[GOSUB]] procedures AFTER the main program code [[END]] or after an [[EXIT SUB]] or [[EXIT FUNCTION]] call. | * To avoid errors, place [[GOSUB]] procedures AFTER the main program code [[END]] or after an [[EXIT SUB]] or [[EXIT FUNCTION]] call. | ||
Line 30: | Line 30: | ||
five: | five: | ||
{{Cl|PRINT}} "Aha! Five!" | {{Cl|PRINT}} "Aha! Five!" | ||
{{Cl|RETURN}} | {{Cl|RETURN}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}} | {{OutputStart}} | ||
Line 49: | Line 49: | ||
''Example 2:'' Returns to a specific line label. | ''Example 2:'' Returns to a specific line label. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|GOSUB}} hey | {{Cl|GOSUB}} hey | ||
{{Cl|PRINT}} "it didn't go here." | {{Cl|PRINT}} "it didn't go here." | ||
hoho: | hoho: | ||
{{Cl|PRINT}} "it went here." | {{Cl|PRINT}} "it went here." | ||
{{Cl|END}} | {{Cl|END}} | ||
hey: | hey: | ||
{{Cl|RETURN}} hoho | {{Cl|RETURN}} hoho | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{ | {{Small|Code by Cyperium}} | ||
{{OutputStart}} | {{OutputStart}} | ||
it went here. | it went here. | ||
Line 64: | Line 64: | ||
{{PageSeeAlso}} | |||
* [[GOSUB]], [[GOTO]] | * [[GOSUB]], [[GOTO]] | ||
* [[RESUME]] | * [[RESUME]] |
Latest revision as of 22:45, 11 February 2023
RETURN is used in GOSUB procedures to return to the original call code line or a specified line label.
Syntax
- RETURN [{linelabel|linenumber}]
Parameters
- RETURN without parameters returns to the code immediately following the original GOSUB call.
- line number or linelabel after the RETURN statement returns code execution to that label.
Usage:
- Normally required at the end of a GOSUB procedure unless the procedure returns using a loop.
- RETURN is not used in error handling procedures. Error procedures use RESUME line number or RESUME NEXT.
- GOSUB procedures use line numbers or line labels designated with a colon after the number or label.
- If RETURN is encountered without a previous GOSUB call a "RETURN without GOSUB" error is produced.
- To avoid errors, place GOSUB procedures AFTER the main program code END or after an EXIT SUB or EXIT FUNCTION call.
Example 1: Returns after a Gosub.
FOR a = 1 TO 10 PRINT a IF a = 5 THEN GOSUB five NEXT END 'END or SYSTEM stop the program before the execution of a sub procedure five: PRINT "Aha! Five!" RETURN |
1 2 3 4 5 Aha! Five! 6 7 8 9 10 |
Example 2: Returns to a specific line label.
GOSUB hey PRINT "it didn't go here." hoho: PRINT "it went here." END hey: RETURN hoho |
it went here. |
See also