Quick start manual

4-20
Delphi Language Guide
Declarations and statements
When you use a function call in this way, its return value is discarded.
For more information about procedures and functions, see Chapter 6, “Procedures
and functions”.
Goto statements
A goto statement, which has the form
goto label
transfers program execution to the statement marked by the specified label. To mark
a statement, you must first declare the label. Then precede the statement you want to
mark with the label and a colon:
label: statement
Declare labels like this:
label label;
You can declare several labels at once:
label label
1
, ..., label
n
;
A label can be any valid identifier or any numeral between 0 and 9999.
The label declaration, marked statement, and goto statement must belong to the same
block. (See “Blocks and scope” on page 4-29.) Hence it is not possible to jump into or
out of a procedure or function. Do not mark more than one statement in a block with
the same label.
For example,
label StartHere;
ƒ
StartHere: Beep;
goto StartHere;
creates an infinite loop that calls the Beep procedure repeatedly.
Aditionally, it is not possible to jump into or out of a try/finally or try/except
statement.
The goto statement is generally discouraged in structured programming. It is,
however, sometimes used as a way of exiting from nested loops, as in the following
example.
procedure FindFirstAnswer;
var X, Y, Z, Count: Integer;
label FoundAnAnswer;
begin
Count := SomeConstant;
for X := 1 to Count do
for Y := 1 to Count do
for Z := 1 to Count do
if ... { some condition holds on X, Y, and Z } then
goto FoundAnAnswer;