Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə51/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   47   48   49   50   51   52   53   54   ...   294
DelphiLanguageGuide

Procedure and Function Calls
A procedure call consists of the name of a procedure (with or without qualifiers), followed by a parameter list (if
required). Examples include
PrintHeading;
Transpose(A, N, M);
Find(Smith, William);
Writeln('Hello world!');
DoSomething();
Unit1.SomeProcedure;
TMyObject.SomeMethod(X,Y);
With extended syntax enabled (
{$X+}
), function calls, like calls to procedures, can be treated as statements in their
own right:
MyFunction(X);
When you use a function call in this way, its return value is discarded.
For more information about procedures and functions, see 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
32


Declare labels like this:
label
 label;
You can declare several labels at once:
label
 label1, ..., labeln;
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,
below.) 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.
Additionally, 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;
        ... { Code to execute if no answer is found }
        Exit;
FoundAnAnswer:
        ... { Code to execute when an answer is found }
end;
Notice that we are using goto to jump out of a nested loop. Never jump into a loop or other structured statement,
since this can have unpredictable effects.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   47   48   49   50   51   52   53   54   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin