{{htmlmetatags>metatag-robots=()
metatag-title=(GOTO | ugBASIC User Manual)
metatag-keywords=(ugBASIC,Commodore 64,Commodore PLUS/4,ZX Spectrum)
metatag-description=(Manual page for GOTO)
metatag-media-og:image=(:ugbasic:logo-ugbasic-fb.png)
metatag-og:title=(GOTO | ugBASIC User Manual)
metatag-og:description=(Manual page for GOTO)
}}
====== 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:
* ''[[https://github.com/spotlessmind1975/ugbasic/tree/main/examples/control_uncond_jumps_01.bas|control_uncond_jumps_01.bas]]''
* ''[[https://github.com/spotlessmind1975/ugbasic/tree/main/examples/control_uncond_jumps_02.bas|control_uncond_jumps_02.bas]]''
* ''[[https://github.com/spotlessmind1975/ugbasic/tree/main/examples/control_returning_01.bas|control_returning_01.bas]]''
* ''[[https://github.com/spotlessmind1975/ugbasic/tree/main/examples/control_returning_02.bas|control_returning_02.bas]]''
==== 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 [[https://github.com/spotlessmind1975/ugbasic/issues/new?title=ISSUE ON GOTO|open an issue]] for this keyword on GitHub. Thank you!===== POWERED BY =====
[[:ugbasic:user:index|{{ :ugbasic:user:logo-ugbasic.png?nolink&600 |}}]]