Table of Contents

ugBASIC User Manual

GOTO ✓

SYNTAX

   GOTO label
   GOTO number

PURPOSE

The GOTO command is a statement that allows you to jump unconditionally to another part of the program. In practice, instead of executing the instructions in sequence, the program “jumps” directly to the line indicated by the GOTO command.

Despite its simplicity, indiscriminate use of the GOTO command can lead to several problems. It can make the code very difficult to follow and understand, creating so-called “spaghetti code”. If a program contains many unconditional jumps, it can become very difficult to find the source of an error. Frequent use of GOTO tends to create a poorly structured flow of control that is difficult to maintain.

The ugBASIC offers more sophisticated and readable control structures, such as: IF…THEN…ELSE, FOR…NEXT, DO…LOOP, and so on. These structures make the code clearer and make it easier to manage the flow of control.

In some specific cases, however, the use of GOTO can be justified, for example in very specific situations, a GOTO can be used to exit a nested loop more efficiently. In some cases, a GOTO can be used to handle errors in the most direct way. In general, it is advisable to avoid the use of GOTO and prefer more modern control structures. A well-structured and readable code is easier to maintain and to change over time.

EXAMPLE

  GOTO nuovaEtichetta
  GOTO 42

See also the following example files:

ABBREVIATION

 Go

AVAILABLE ON

ANY PROBLEM?

If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!

POWERED BY