Exit

Command

Not Applicable

Description

The Exit block leaves a block list immediately rather than finishing the rest of the list. The Exit block has no tab on the bottom for snapping since no other block behavior follows an Exit bock. Exit blocks can be used to abandon a block list or to reduce the nesting level of conditional statements. Although often used within loops the Exit block should not be confused with the C language "Break" command. Exit does not just exit the loop, it exits the entire procedure and is more like the C language "return". Exit should not be used in the Try or Recover sections of a Try Recover command. Use the Escape command instead.

Escapes

The Exit block does not produce any escapes.

Examples

Exit can be helpful when a problem is discovered inside of loops and it is best to just stop. In this example a sealant cartridge runs dry in the middle of a run. It is best to just exit and not continue running the remaining loop count without sealant.

An alternative way to do this without Exit looks like this:

However this requires the introduction of a counter variable, a number of blocks to manage the counter, and a more involved logical expression to determine if the process should continue or not. If additional reasons to stop were introduced the logical expression would get more involved. The Exit block allows various termination reasons to be added as individual cases in relative isolation from each other.

Consider a case where an involved process should terminate at the moment required criteria are not met. One approach is to sustain the process through the ongoing judgement that all requirements are being met such as shown here:

Alternatively a process can be terminated by identifying requirements are not met and exiting. The termination behavior is accomplished with the Exit block. This has the conditional depth shallower as shown here:

Another approach may be to use an exception for early termination through a separate procedure that checks and which could be directly called from procedure Perform_Process:

Note how the exception approach leaves the "normal operation" description of the process simpler and less disrupted by error considerations.

Related Topics

Try Recover
Escape
Escape Code Constants
Loop