Specifications
Commands - 42
EXIT and EXIT CLEAR
Statement
SYNTAX: EXIT [line/label]
EXIT CLEAR
PURPOSE: To allow legal branching out of a loop structure.
REMARKS: Within FOR/NEXT, GOSUB/RETURN and DO/UNTIL structures, it is sometimes necessary to exit
the loop before the loop conditions are met.
EXIT CLEAR resets all stacks. It can be used in emergency stop (etc.) situations where the nesting
of loop structures cannot be known.
EXIT is always used with a line/label unless two or more levels are to be exited. When multiple
EXITs are used, the last one must have a line/label.
EXAMPLE: 10 GOSUB 50
50 EXIT:GOTO 10
60 RETURN
Without the EXIT statement, the system would eventually crash, as the RETURN statement would
never be reached.
10 GOSUB 20
20 GOSUB 30
30 EXIT : EXIT 50
40 RETURN
50 GOTO 10
In this case there is a nested GOSUB structure. EXIT must be executed one time for each level of
nesting. Failure to include two EXITs would have caused a stack imbalance on each pass.
Eventually, you would get a “Nesting” error message.
ERROR: <Can’t compile> – if line/label does not exist
<Syntax> – Trying to exit a nonexistent loop