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.
GOTO label GOTO number
Join BASIC 10Liner Contest with ugBASIC!
An interesting competition is held at the beginning of each year: the
BASIC 10Liner Contest.
It is possible to use ugBASIC to participate in the next
"BASIC10Liner" competition, in the following categories:
GOTO ↔ Go
If you have found a problem with this keyword, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO KEYWORDS