Difference between revisions of "End"

From Free Pascal wiki
Jump to navigationJump to search
Line 11: Line 11:
 
   end;
 
   end;
 
</delphi>
 
</delphi>
 +
 +
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):
 
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):
Line 50: Line 52:
 
   
 
   
 
   end.
 
   end.
 +
</delphi>
 +
 +
It also closes a [[Record|record]]:
 +
<delphi>
 +
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;
 
</delphi>
 
</delphi>
  
 
{{Keywords}}
 
{{Keywords}}

Revision as of 23:06, 26 October 2010

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: <delphi>

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

</delphi>

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):

<delphi>

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

</delphi>

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

<delphi>

 unit detent;
 uses math;

 procedure delta(r:real);

 implementation

 procedure delta;
 begin

 ...

 end;

 ...

(* Note: No begin statement *)

 end.

</delphi>

It also closes a record: <delphi>

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;

</delphi>


Keywords: begindoelseendforifrepeatthenuntilwhile