| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords (divide) (equal) (less) (minus) (more) (multiply) (plus) (power) Abs And Append Asc Atn Auto Backup Bank Begin Bend Bload Boot Box Bsave Bump Catalog Char Chr Circle Close Clr Cmd Collect Collision Color Concat Cont Copy Cos Data Dclear Dclose Dec Def Delete Dim Directory Dispose Dload Do Dopen Draw Ds Ds string Dsave Dverify El Else End Envelope Er Err Exit Exp Fast Fetch Filter Fn For Fre Get Get num Getkey Go Gosub Goto Graphic Gshape Header Help Hex If Input Input num Instr Int Joy Key Left Len Let List Load Locate Log Loop Mid Monitor Movspr New Next Not Off On Open Or Paint Peek Pen Pi Play Pointer Poke Pos Pot Print num Pudef Quit Rclr Rdot Read Record Rem Rename Renumber Restore Resume Return Rgr Right Rlum Rnd Rreg Rspcolor Rsppos Rsprite Run Rwindow Save Scale Scnclr Scratch Sgn Sin Sleep Slow Sound Spc Sprcolor Sprdef Sprite Sprsav Sqr Sshape St Stash Step Stop Str Swap Sys Tab Tan Tempo Then Ti Ti string To Trap Troff Tron Until Using Usr Val Verify Vol Wait While Width Window Xor Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
RETURN
Program flow control; exit a subroutine.
RETURN searches the BASIC statck for the most recent GOSUB entry. Should it be found, the location of the next BASIC statement is set from the value stored on the stack, and the stack entry (along with any entries that were skipped to find the GOSUB entry) are removed from the stack. If no GOSUB entry is found on the stack, a RETURN WITHOUT GOSUB ERROR should be generated (there seems to be a bug in some versions that will crash the interpreter instead). Unfortunately, no parameters are allowed. This makes exiting through multiple levels difficult. BASIC 4.7 (only) has the DISPOSE command which can remove an entry from the BASIC stack. In other versions, a kludgy method is to use another command that places entries on the BASIC stack (such as FOR or DO) before invoking a GOSUB. Then if the RETURN needs to escape multiple levels, a corresponding (NEXT or LOOP) can be used which will discard all the GOSUB entries on the stack in order to get back to initial FOR/DO statement. If that sounds confusing, then now you know why I call it a kludge! Example 1:
RETURN is normally only used as statement (i.e., inside a program). Attempting to use it as command (in direct mode) will usually generate the RETURN WITHOUT GOSUB ERROR (or crash the system). However, if the program was stopped while inside a subroutine (with either the STOP statement or the STOP key) then RETURN will search for and remove the GOSUB entry stored on the stack (as described above), but it fails to actually set the location for the next statement to be executed and also fails to switch the interpreter into RUN Mode. It seems that BASIC fails to update its own secret variable on some machines. It actually works fine in BASIC v2, but fails on BASIC v3.5 or later. Example 2 (Plus/4 or C128):
Example 2A (C64):
© H2Obsession, 2014 |