Goto
 
Control flow statement to jump to another part of the program

Syntax

Goto label

Description

Jumps code execution to a line label.

When using Goto label to exit a scope, any local variables defined in that scope are destroyed (destructors are called).

Usage of Goto label may be disallowed when it skips a variable definition but not the end of the variable's scope. If the variable requires construction, a compiler error is shown. For other variables, a compiler warning is shown. This is intended to prevent potential accesses to uninitialized variables, and ensures that automatic destruction never happens to an uninitialized variable.

For better source code readability, overuse of Goto should be avoided in favor of more modern structures such as Do...Loop, For...Next, Sub, and Function.

Example

    Goto there

backagain:
    End

there:
    Print "Welcome!"
    Goto backagain


'' Compile with -lang qb or fblite

'$lang: "qb"

1 Goto 3
2 End
3 Print "Welcome!"
4 Goto 2


Dialect Differences

  • Line numbers are allowed only in the -lang qb and -lang deprecated dialects.
  • In the -lang qb and -lang fblite dialects, Goto label is allowed to skip any variable definitions, because nested scopes are not supported and all variable definitions are moved to the top of their procedure.

Differences from QB

  • None

See also