Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Command: Exit from REPEAT loop immediately.

((PUBPRI))
   QUIT

...

...

Explanation

QUIT is one of two commands (NEXT and QUIT) that affect REPEAT loops. QUIT causes a REPEAT loop to terminate immediately.

...

Using QUIT

QUIT is typically used as an exception case, in a conditional statement, in REPEAT loops to terminate the loop prematurely. For example, assume that DoMore and SystemOkay are methods created elsewhere that each return Boolean values:

Code Block
repeat while DoMore              'Repeat while more to do

...


  !outa[0]                       'Toggle status light

...


  <do something>                 'Perform some task

...


  if !SystemOkay

...


    quit                         'If system failure, exit
  <more code here>               'Perform other tasks 

The above code toggles a status light on P0 and performs other tasks while the DoMore method returns TRUE. However, if the SystemOkay method returns FALSE partway through the loop, the IF statement executes the QUIT command which causes the loop to terminate immediately.

The QUIT command can only be used within a REPEAT loop; an error will occur otherwise.