bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
EXIT Statement Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses EXIT statements to exit a variety of control-flow
'structures. A loop is continuously executed until you press any key.
'Once a key is pressed, the next EXIT statement that executes will cause
'the program to end.
 
DECLARE SUB ExitDemo ()
CLS
DO
    PRINT : PRINT "Entering/Reentering ExitDemo"
    ExitDemo
    SLEEP 1
 
LOOP WHILE INKEY$ = ""
PRINT "Exiting 'EXIT' example program"
 
SUB ExitDemo
    DO
        FOR I% = 1 TO 1000
            Num% = INT(RND * 100)
            SELECT CASE Num%
                CASE 7
                    PRINT "Exiting For...Next Loop in ExitDemo SUB"
                    EXIT FOR
                CASE 29
                    PRINT "Exiting Do...Loop in ExitDemo SUB"
                    EXIT DO
                CASE 54
                    PRINT "Exiting ExitDemo SUB"
                    EXIT SUB
                CASE ELSE
            END SELECT
        NEXT I%
    LOOP
END SUB