Difference between revisions of "End"

From Free Pascal wiki
Jump to navigationJump to search
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 2: Line 2:
  
 
For example:
 
For example:
<delphi>
+
<syntaxhighlight>
 
   procedure Proc1;
 
   procedure Proc1;
 
    
 
    
Line 10: Line 10:
 
     (..)
 
     (..)
 
   end;
 
   end;
</delphi>
+
</syntaxhighlight>
  
 
The end statement is one of the exceptions to the rule that every statement must be followed by a semicolon.  The statement immediately preceding an end statement does not require a semicolon.
 
The end statement is one of the exceptions to the rule that every statement must be followed by a semicolon.  The statement immediately preceding an end statement does not require a semicolon.
Line 16: Line 16:
 
It is also used to end a pascal source file, in which case it is followed by a period rather than a [[;|semicolon]]  (in the example below, the last semicolon is optional):
 
It is also used to end a pascal source file, in which case it is followed by a period rather than a [[;|semicolon]]  (in the example below, the last semicolon is optional):
  
<delphi>   
+
<syntaxhighlight>   
 
   program Proc2;
 
   program Proc2;
 
   var
 
   var
Line 28: Line 28:
 
     end;
 
     end;
 
   end.
 
   end.
</delphi>
+
</syntaxhighlight>
  
 
For a UNIT which contains no initialization, END is used to indicate the end of the unit:
 
For a UNIT which contains no initialization, END is used to indicate the end of the unit:
  
<delphi>
+
<syntaxhighlight>
 
   unit detent;
 
   unit detent;
 
   uses math;
 
   uses math;
Line 52: Line 52:
 
   
 
   
 
   end.
 
   end.
</delphi>
+
</syntaxhighlight>
  
 
It also closes a [[Record|record]]:
 
It also closes a [[Record|record]]:
<delphi>
+
<syntaxhighlight>
 
  Type
 
  Type
 
   ExampleRecord = Record
 
   ExampleRecord = Record
Line 62: Line 62:
 
                     Average: Real { holds the average or mean of the values in the array }
 
                     Average: Real { holds the average or mean of the values in the array }
 
                   End;
 
                   End;
</delphi>
+
</syntaxhighlight>
  
 
{{Keywords}}
 
{{Keywords}}

Revision as of 15:08, 24 March 2012

The end keyword closes a Block of instructions started with the begin or case keyword, ends the declaration of fields of a record, or closes a try .. finally or try .. except construct. It is also used to close a unit having no initialization code.

For example:

  procedure Proc1;
  
  var a,b: integer;
  
  begin
    (..)
  end;

The end statement is one of the exceptions to the rule that every statement must be followed by a semicolon. The statement immediately preceding an end statement does not require a semicolon.

It is also used to end a pascal source file, in which case it is followed by a period rather than a semicolon (in the example below, the last semicolon is optional):

   
  program Proc2;
  var
    SL: TStrings;
  begin
    SL := TStringlist.Create;
    try
      (..)
    finally
      SL.Free;
    end;
  end.

For a UNIT which contains no initialization, END is used to indicate the end of the unit:

  unit detent;
  uses math;
 
  procedure delta(r:real);
 
  implementation
 
  procedure delta;
  begin
 
  ...
 
  end;
 
  ...
 
 (* Note: No '''begin''' statement *)
 
  end.

It also closes a record:

 Type
   ExampleRecord = Record
                     Values: array [1..200] of real;
                     NumValues: Integer; { holds the actual number of points in the array }
                     Average: Real { holds the average or mean of the values in the array }
                   End;


Keywords: begindoelseendforifrepeatthenuntilwhile