Difference between revisions of "End"

From Lazarus wiki
Jump to navigationJump to search
 
m (replace legacy syntaxhighlight syntax; fix spelling mistake; fix syntax)
 
(17 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[keyword]] which closes a block of instructions started with the [[begin]] keyword, or the [[try]] .. [[finally]] or [[try]] .. [[except]] constructs.
+
{{end}}
 
+
 
 +
The [[Keyword|keyword]] <syntaxhighlight lang="pascal" inline>end</syntaxhighlight> terminates an entity.
 +
It appears at several occasions:
 +
 
 +
* to mark the end of a module, i.e. a [[Program|<syntaxhighlight lang="pascal" inline>program</syntaxhighlight>]], [[Unit|<syntaxhighlight lang="pascal" inline>unit</syntaxhighlight>]] or [[Library|<syntaxhighlight lang="pascal" inline>library</syntaxhighlight>]]
 +
* to conclude a [[Block|block]] of statements or instructions respectively
 +
** either started by [[Begin|<syntaxhighlight lang="pascal" inline>begin</syntaxhighlight>]], or
 +
** started by [[Asm|<syntaxhighlight lang="delphi" inline>asm</syntaxhighlight>]]
 +
* to wrap up some language constructs:
 +
** most prominently [[If and Then|<syntaxhighlight lang="pascal" inline>if … then … end</syntaxhighlight>]], or
 +
** [[Case|<syntaxhighlight lang="pascal" inline>case</syntaxhighlight>]] … [[Of|<syntaxhighlight lang="pascal" inline>of</syntaxhighlight>]] … <syntaxhighlight lang="pascal" inline>end</syntaxhighlight>, but also
 +
** [[Try, Except and Finally|<syntaxhighlight lang="delphi" inline>try … except … finally … end</syntaxhighlight>]]
 +
* to finish off certain [[Type|type]] declarations, such as [[Object|<syntaxhighlight lang="delphi" inline>object</syntaxhighlight>]], [[Record|<syntaxhighlight lang="pascal" inline>record</syntaxhighlight>]] and [[Class|<syntaxhighlight lang="delphi" inline>class</syntaxhighlight>]]
 +
* in [[Extended Pascal|extended Pascal]] <syntaxhighlight lang="pascal" inline>to end do …</syntaxhighlight> starts the definition of the [[Finalization|<syntaxhighlight lang="pascal" inline>finalization</syntaxhighlight> part of a module]]
 +
 
 
For example:
 
For example:
  
  '''program''' Project1;
+
<syntaxhighlight lang="pascal" highlight="6">
 
+
procedure proc0;
  '''var''' a,b: integer;
+
var
 
+
a, b: integer;
  '''begin'''
+
begin
    (..)
+
  '''end'''.
+
end;
 +
</syntaxhighlight>
 +
 
 +
The <syntaxhighlight lang="pascal" inline>end</syntaxhighlight> gloss is one of the exceptions to the rule that every statement must be followed by a [[Semicolon|semicolon]].
 +
The statement immediately preceding an <syntaxhighlight lang="pascal" inline>end</syntaxhighlight> does not require a semicolon.
  
  '''var'''
+
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):
    SL: TStrings;
+
<syntaxhighlight lang="delphi" highlight="10,11">
  '''begin'''
+
program proc1;
    SL := TStringlist.Create;
+
var
    '''try'''
+
SL: TStrings;
      (..)
+
begin
    '''finally'''
+
SL := TStringlist.create;
      SL.Free;
+
try
    '''end''';
+
  '''end''';
+
finally
 +
SL.free;
 +
end;
 +
end.
 +
</syntaxhighlight>
  
It is also used to end a pascal source file, in which case it is followed by a period rather than a [[semi-colon]].
+
<syntaxhighlight lang="pascal" inline>end</syntaxhighlight> is used to indicate the end of the unit:
 +
<syntaxhighlight lang=pascal>
 +
  unit detent;
 +
  uses math;
 +
 +
  procedure delta(r:real);
 +
 +
  implementation
 +
 +
  procedure delta;
 +
  begin
 +
 +
  ...
 +
 +
  end;
 +
 +
  ...
 +
  (* Note: No corresponding '''begin''' statement *)
 +
 +
  end.
 +
</syntaxhighlight>
  
 +
It also closes a [[Record|record]]:
 +
 +
<syntaxhighlight lang="pascal">
 +
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;
 +
</syntaxhighlight>
  
 
{{Keywords}}
 
{{Keywords}}
 
{{stub}}
 

Latest revision as of 23:49, 24 June 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