Branching statements
- Transferring control with the GoTo statement
The branching statement GoTo transfers control unconditionally. - Using the If...GoTo...Else statement to transfer unconditionally
The branching statement If...GoTo...Else is a convenient way to abbreviate a statement that would otherwise be written If...Then GoTo label Else. It can be used when the only action you want to take in the Then clause of an If...Then...Else statement is to transfer unconditionally. The description of If...Then...Else applies to this statement, with the GoTo clause substituted for the Then clause. The statement must be written on one line. - Conditional control transfer with the On...GoTo statement
The branching statement On...GoTo transfers control conditionally. - Transferring control within the same procedure with the GoSub, On...GoSub, and Return statements
The branching statements GoSub and On...GoSub are nonstandard programming techniques with limited usefulness. They enable running a group of statements by transferring control from any number of other locations within the same procedure. Functionally the statements behave as a subroutine, but they can't take arguments, don't establish a separate scope, and aren't available from other procedures or scripts. It is more common and useful to write the statements as an ordinary sub.
Parent topic: Managing Flow in Scripts
Related concepts: