Exit and exit clear – Remote Processing CAMBASIC User Manual
Page 79

Comm ands - 46
EXIT and EXIT CLEAR
Statement
SYNTAX:
EXIT [line/label]
EXIT CLEAR
PURPOSE:
To allow legal branching out of a loop structure.
REMARK S:
Within F OR/ NEX T, GOSU B/RE TUR N and D O/U NTI L struc tures, it is sometim es necessar y to exit
the loop befor e the loop cond itions are m et.
EXIT C LEAR 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 mor e levels ar e to be exited. When m ultiple
EXITs are used, the last one must have a line/label.
EXIT does not work in a DO/E NDD O structure.
EXAMPLE:
10 GOSUB 50
50 EXIT:GOTO 10
60 RETURN
Without the E XIT sta tement, the system w ould eventua lly crash, as the RE TUR N statem ent 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. E XIT must be executed one time for each level of
nesting. F ailure to include two E XITs w ould have caused a stack im balance on each pass.
Eventually, you would get a “Nesting” error message.
ERROR:
< Can’t compile> – if line/labe l does not exist
< Syntax> – Trying to exit a non-recognized loop or structure