EXIT |
Syntax: {IF Condition THEN} EXIT
Function
Causes the immediate termination of a loop construct (FOR...NEXT or
DO...LOOP) when Condition evaluates as True.
Explanation
The EXIT command allows a program to terminate a loop construct before the
loop limit test is executed. For example:
Main: FOR idx = 1 TO 15 IF idx > 9 THEN EXIT SEROUT TX, Baud, "*" NEXT
In this program, the FOR idx = 1 TO 15 loop will not run past nine because the IF idx > 9 THEN EXIT contained within will force the loop to terminate when idx is greater than nine. Note that the EXIT command only terminates the loop that contains it. In the the program above, only nine asterisks will be transmitted on the TX pin.
Here is the DO...LOOP version of the same program:
Start: idx = 1 Main: DO IF idx > 9 THEN EXIT SEROUT TX, Baud, "*" INC idx LOOP WHILE idx <= 15
EXIT may also be used by itself when part of a larger IF...THEN...ENDIF or DO...LOOP block:
IF idx > 9 THEN SEROUT TX, Baud, CR idx = 1 EXIT ENDIF
Related Instructions: FOR...NEXT, DO...LOOP, and IF...THEN