End: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 1 | + | The [[Keyword|keyword]] `end` terminates an entity. It appears at several occasions: | |
| 2 | 2 | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 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 | 13 | ||
| 14 | - | ||
| 15 | - | ||
| 14 | + | For example: | |
| 15 | + | ||
| 16 | + | ``` pascal | |
| 16 | 17 | procedure proc0; | |
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 18 | + | var | |
| 19 | + | a, b: integer; | |
| 20 | + | begin | |
| 21 | + | … | |
| 22 | + | end; | |
| 22 | 23 | ``` | |
| 23 | 24 | ||
| 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. | |
| 25 | 26 | ||
| 26 | - | ||
| 27 | - | ||
| 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 | |
| 28 | 30 | program proc1; | |
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 31 | + | var | |
| 32 | + | SL: TStrings; | |
| 33 | + | begin | |
| 34 | + | SL := TStringlist.create; | |
| 35 | + | try | |
| 36 | + | … | |
| 37 | + | finally | |
| 38 | + | SL.free; | |
| 39 | + | end; | |
| 40 | + | end. | |
| 39 | 41 | ``` | |
| 40 | 42 | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 43 | + | `end` is used to indicate the end of the unit: | |
| 62 | 44 | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - | ||
| 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. | |
| 71 | 64 | ``` | |
| 72 | 65 | ||
| 73 | - | ||
| 74 | - | ||
| 66 | + | It also closes a [[Record|record]]: | |
| 75 | 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 | + | ||
| 76 | 77 | --- | |
| 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).* |
