Difference between revisions of "End"

From Lazarus wiki
Jump to navigationJump to search
(add back comment)
(structure first paragraph by using a list)
Line 1: Line 1:
 
{{end}}
 
{{end}}
<br>
+
 
The '''end''' [[Keyword|keyword]] closes a [[Block]] of instructions started with the [[Begin|begin]] or [[Case|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.
+
The [[Keyword|keyword]] <syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight> terminates an entity.
 +
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 conclude a [[Block|block]] of statements or instructions respectively
 +
** either started by [[Begin|<syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight>]], or
 +
** started by [[Asm|<syntaxhighlight lang="delphi" enclose="none">asm</syntaxhighlight>]]
 +
* to wrap up some language constructs:
 +
** most prominently [[If and Then|<syntaxhighlight lang="pascal" enclose="none">if … then … end</syntaxhighlight>]], or
 +
** [[Case|<syntaxhighlight lang="pascal" enclose="none">case</syntaxhighlight>]] [[Of|<syntaxhighlight lang="pascal" enclose="none">of</syntaxhighlight>]] … <syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>, but also
 +
** [[Try, Except and Finally|<syntaxhighlight lang="delphi" enclose="none">try … except … finally … end</syntaxhighlight>]]
 +
* to finish off certain [[Type|type]] declarations, such as [[Object|<syntaxhighlight lang="delphi" enclose="none">object</syntaxhighlight>]], [[Record|<syntaxhighlight lang="pascal" enclose="none">record</syntaxhighlight>]] and [[Class|<syntaxhighlight lang="delphi" enclose="none">class</syntaxhighlight>]]
  
 
For example:
 
For example:
<syntaxhighlight>
+
<syntaxhighlight lang="pascal" highlight="6">
  procedure Proc1;
+
procedure proc0;
 
+
var
  var a,b: integer;
+
a, b: integer;
 
+
begin
  begin
+
    (..)
+
end;
  end;
 
 
</syntaxhighlight>
 
</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 <syntaxhighlight lang="pascal" enclose="none">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" enclose="none">end</syntaxhighlight> 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):
 
  
<syntaxhighlight>  
+
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 Proc2;
+
<syntaxhighlight lang="delphi" highlight="10,11">
  var
+
program proc1;
    SL: TStrings;
+
var
  begin
+
SL: TStrings;
    SL := TStringlist.Create;
+
begin
    try
+
SL := TStringlist.create;
      (..)
+
try
    finally
+
      SL.Free;
+
finally
    end;
+
SL.free;
  end.
+
end;
 +
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
END 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>
 
   unit detent;
 
   unit detent;
Line 66: Line 74:
  
 
{{Keywords}}
 
{{Keywords}}
<br>
 
<br>
 
  
 
[[category:Pascal]]
 
[[category:Pascal]]
 
[[Category:Control Structures]]
 
[[Category:Control Structures]]

Revision as of 16:52, 14 October 2018

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