Exit

Syntax options:

    Exit Sub | Exit Function | Exit Do | Exit For | Exit Repeat

Command Availability:

Available on all microcontrollers.

Explanation:

This command makes the program exit the routine or loop it is currently in, as if it had reached the end of that routine or loop.

It applies to subroutines, functions, For-Next loops, Do-Loop loops, and Repeat loops — use the form matching what you want to exit (Exit Sub, Exit Function, Exit Do, Exit For, or Exit Repeat).

Example:

    #chip tiny13, 1

    #define SENSOR PORTB.0
    #define BUZZER PORTB.1
    #define LIGHT PORTB.2
    Dir SENSOR In
    Dir BUZZER Out
    Dir LIGHT Out

    Do
      Burglar
    Loop

    'Burglar Alarm subroutine
    Sub Burglar
      If SENSOR = 0 Then
        Set BUZZER Off
        Set LIGHT Off
        Exit Sub          ' <<< the Exit instruction
      End If
      Set BUZZER On
      Set LIGHT On
    End Sub

Key line: Exit Sub — leaves Burglar immediately once the sensor reads clear, so the two lines that would otherwise switch the buzzer and light on are skipped.

See Also:

  • Do — the loop form exited with Exit Do
  • For — the loop form exited with Exit For
  • Repeat — the loop form exited with Exit Repeat
  • Sub — the routine form exited with Exit Sub, as used above
  • Functions — the routine form exited with Exit Function