Difference between revisions of "End"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 1: Line 1:
The '''end''' [[Keyword|keyword]] closes a block of instructions started with the [[Begin|begin]] or [[case]] keyword, ends the declaration of [[field]]s of a [[record]], or closes a [[try]] .. [[finally]] or [[try]] .. [[except]] construct.  It is also used to close a unit having no initialization code.
+
The '''end''' [[Keyword|keyword]] closes a block of instructions started with the [[Begin|begin]] or [[case]] keyword, ends the declaration of [[field]]s of a [[Record|record]], or closes a [[Try|try]] .. [[Finally|finally]] or [[Try|try]] .. [[Except|except]] construct.  It is also used to close a [[Unit|unit]] having no initialization code.
  
 
For example:
 
For example:
 
+
<delphi>
   '''procedure''' Proc1;
+
   procedure Proc1;
 
    
 
    
   '''var''' a,b: integer;
+
   var a,b: integer;
 
    
 
    
   '''begin'''
+
   begin
 
     (..)
 
     (..)
   '''end''';
+
   end;
 +
</delphi>
  
 
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):
 
+
 
   '''program''' Proc2;
+
<delphi> 
   '''var'''
+
   program Proc2;
 +
   var
 
     SL: TStrings;
 
     SL: TStrings;
   '''begin'''
+
   begin
 
     SL := TStringlist.Create;
 
     SL := TStringlist.Create;
     '''try'''
+
     try
 
       (..)
 
       (..)
     '''finally'''
+
     finally
 
       SL.Free;
 
       SL.Free;
     '''end''';
+
     end;
   '''end'''.
+
   end.
 +
</delphi>
  
 
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:
  
   '''unit''' detent;
+
<delphi>
   '''uses''' math;
+
   unit detent;
 +
   uses math;
 
   
 
   
   '''procedure''' delta(r:real);
+
   procedure delta(r:real);
 
   
 
   
   '''implementation'''
+
   implementation
 
   
 
   
   '''procedure''' delta;
+
   procedure delta;
   '''begin'''
+
   begin
 
   
 
   
 
   ...
 
   ...
 
   
 
   
   '''end''';
+
   end;
 
   
 
   
 
   ...
 
   ...
Line 46: Line 50:
 
   
 
   
 
   end.
 
   end.
 
+
</delphi>
  
 
{{Keywords}}
 
{{Keywords}}

Revision as of 07:54, 17 October 2007

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>

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>


Keywords: begindoelseendforifrepeatthenuntilwhile