Flow control statements

The flow control statements that alter the flow of execution fall into several functional groups:

  • The block statements If...Then...Else, If...Then...ElseIf, and Select Case

    These specify executing a group of subsidiary statements, depending on specified conditions.

  • The branching statements GoTo, If...GoTo...Else, On...GoTo, GoSub, On...GoSub, and Return

    These specify continuing execution at some other point in the script, possibly depending on specified conditions.

  • The iterative block statements Do, For, ForAll, and While

    These specify repeating a group of subsidiary statements some number of times, or while or until some specified condition is satisfied.

  • The early termination statements End and Exit

    These specify returning from a procedure, or ending execution of a Do, For, or ForAll statement, before execution reaches the statement that ends the procedure or the statement.

The remaining sections in this chapter discuss these statements in the order listed previously.

There is no built-in limit on the level or type of nesting of these statements. For example, a Do statement may contain another Do statement that contains a third Do statement, or a Do statement may contain a For statement that contains another Do statement.