User Tools

Site Tools


break_immediately_leave_loop_.htm
Navigation:  Language Reference > 12 - Execution Control > Execution Control Statements >====== BREAK (immediately leave loop) ====== Previous pageReturn to chapter overviewNext page

 

BREAK [ label ]

blk2blue.jpg

BREAK Transfers control to the first statement following the terminator of a LOOP or ACCEPT structure.
label The label on the LOOP or ACCEPT statement from which to break. This must be the label of a nested loop structure containing the BREAK statement.

The BREAK statement immediately terminates processing in the LOOP or ACCEPT structure and transfers control to the first statement following the terminating END, WHILE, or UNTIL statement of the LOOP, or the terminating END statement of the ACCEPT structure.

BREAK may only be used in a LOOP or ACCEPT loop structure. The use of the optional label argument allows you to cleanly break out of multiple levels of nested loops, eliminating one common use of GOTO.

Example:

LOOP                     !Loop

 ASK                     !wait for a keystroke

 IF KEYCODE() = EscKey   !if Esc key pressed

  BREAK                  !break out of the loop

 ELSE                    !otherwise

  BEEP                   !sound the alarm

 END  

END  

Loop1 LOOP                !Loop1 is the label

DO ParentProcess

Loop2  LOOP               !Loop2 is the label

       DO ChildProcess

       IF SomeCondition

        BREAK Loop1      !Break out of both nested loops

       END

      END

     END

   ACCEPT                !ACCEPT loop structure

    CASE ACCEPTED()

    OF ?Ok

     CallSomeProc

    OF ?Cancel

    BREAK               !break out of the loop

    END  

   END  

See Also:

LOOP

CYCLE

ACCEPT

break_immediately_leave_loop_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1