Sign in Join
Wiki copytemporary

End: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: End

OldNewLine
1+The [[Keyword|keyword]] `end` terminates an entity. It appears at several occasions:
2+
3+- to mark the end of a module, i.e. a [[Program|program]], [[Unit|unit]] or [[Library|library]]
4+- to conclude a [[Block|block]] of statements or instructions respectively
5+ - either started by [[Begin|begin]], or
6+ - started by [[Asm|asm]]
7+- to wrap up some language constructs:
8+ - most prominently [[If and Then|if … then … end]], or
9+ - [[Case|case]] … [[Of|of]] … `end`, but also
10+ - [[Try, Except and Finally|try … except … finally … end]]
11+- to finish off certain [[Type|type]] declarations, such as [[Object|object]], [[Record|record]] and [[Class|class]]
12+- in [[Extended Pascal|extended Pascal]] `to end do …` starts the definition of the [[Finalization|finalization part of a module]]
13+
14+For example:
15+
16+``` pascal
17+procedure proc0;
18+var
19+ a, b: integer;
20+begin
21+ …
22+end;
23+```
24+
25+The `end` gloss is one of the exceptions to the rule that every statement must be followed by a [[Semicolon|semicolon]]. The statement immediately preceding an `end` does not require a semicolon.
26+
27+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):
28+
29+```delphi
30+program proc1;
31+var
32+ SL: TStrings;
33+begin
34+ SL := TStringlist.create;
35+ try
36+ …
37+ finally
38+ SL.free;
39+ end;
40+end.
41+```
42+
43+`end` is used to indicate the end of the unit:
44+
45+``` pascal
46+ unit detent;
47+ uses math;
48+
49+ procedure delta(r:real);
50+
51+ implementation
52+
53+ procedure delta;
54+ begin
55+
56+ ...
57+
58+ end;
59+
60+ ...
61+ (* Note: No corresponding '''begin''' statement *)
62+
63+ end.
64+```
65+
66+It also closes a [[Record|record]]:
67+
68+``` pascal
69+ Type
70+ ExampleRecord = Record
71+ Values: array [1..200] of real;
72+ NumValues: Integer; { holds the actual number of points in the array }
73+ Average: Real { holds the average or mean of the values in the array }
74+ End;
75+```
76+
77+---
78+*From the Free Pascal wiki, page "End", as it stood on 2020-06-24 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history