Difference between revisions of "End"

From Free Pascal wiki
Jump to navigationJump to search
(structure first paragraph by using a list)
m (Fixed syntax highlighting; deleted category included in page template)
Line 3: Line 3:
 
The [[Keyword|keyword]] <syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight> terminates an entity.
 
The [[Keyword|keyword]] <syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight> terminates an entity.
 
It appears at several occasions:
 
It appears at several occasions:
 +
 
* to mark the end of a module, i.e. a [[Program|<syntaxhighlight lang="pascal" enclose="none">program</syntaxhighlight>]], [[Unit|<syntaxhighlight lang="pascal" enclose="none">unit</syntaxhighlight>]] or [[Library|<syntaxhighlight lang="pascal" enclose="none">library</syntaxhighlight>]]
 
* to mark the end of a module, i.e. a [[Program|<syntaxhighlight lang="pascal" enclose="none">program</syntaxhighlight>]], [[Unit|<syntaxhighlight lang="pascal" enclose="none">unit</syntaxhighlight>]] or [[Library|<syntaxhighlight lang="pascal" enclose="none">library</syntaxhighlight>]]
 
* to conclude a [[Block|block]] of statements or instructions respectively
 
* to conclude a [[Block|block]] of statements or instructions respectively
Line 14: Line 15:
  
 
For example:
 
For example:
 +
 
<syntaxhighlight lang="pascal" highlight="6">
 
<syntaxhighlight lang="pascal" highlight="6">
 
procedure proc0;
 
procedure proc0;
Line 42: Line 44:
  
 
<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight> is used to indicate the end of the unit:
 
<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight> is used to indicate the end of the unit:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
   unit detent;
 
   unit detent;
 
   uses math;
 
   uses math;
Line 64: Line 66:
  
 
It also closes a [[Record|record]]:
 
It also closes a [[Record|record]]:
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
  Type
 
  Type
 
   ExampleRecord = Record
 
   ExampleRecord = Record
Line 74: Line 77:
  
 
{{Keywords}}
 
{{Keywords}}
 
[[category:Pascal]]
 
[[Category:Control Structures]]
 

Revision as of 08:46, 14 February 2020

Deutsch (de) English (en) suomi (fi) français (fr) русский (ru)

The keyword end terminates an entity. It appears at several occasions:

For example:

procedure proc0;
var
	a, b: integer;
begin
	
end;

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

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

program proc1;
var
	SL: TStrings;
begin
	SL := TStringlist.create;
	try
		
	finally
		SL.free;
	end;
end.

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 corresponding '''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