Last Updated:

Goto Delphi operator

When using if and case statements, the transition to the sequence of instructions of the program being developed is carried out, guided by some pre-known condition. Therefore, these instructions are sometimes called conditional transition instructions.

In addition to these instructions for controlling the process of further progress of the program, there is another operator goto Delphi (unconditional transition instruction). What does the goto Delphi statement look like? The general appearance of the goto Delphi instruction is as follows:

 

goto Tag

 

from where label means some identifier located before the instruction, which is executed without fail after the goto instruction itself. The label encountered in the goto statement must be declared in the label description section (this section begins with the reserved word label and is located before the var variable description section).

In the source code of the program, the programmer puts a label before the instruction to which the transition will subsequently be performed when the goto instruction is executed. Immediately after the entered label, you need to put a colon.

Examples of the goto Delphi operator:

As an example, let's give the already known program for determining a prime number among the numbers entered by the user.

The program's source code in the listing presents a variant of the procedure. The goto instruction is used to complete the procedure when incorrect data has been entered by the user.

In some books on programming, you may find judgments that it is unacceptable to use the goto instruction, since this use can lead to the confusion of the programs created. But it is impossible to agree with this statement objectively.

There are times when the use of the goto instruction is simply necessary and justified. The example of a program using the goto instruction shown above is the case.