End: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 1 | + | The [[Keyword|keyword]] `end` terminates an entity. It appears at several occasions: | |
| 13 | 2 | ||
| 14 | - | ||
| 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 … finally … end`](</index.php?title=Try,_Except_and_Finally&action=edit&redlink=1> "Try, Except and Finally \(page does not exist\)") | |
| 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]] | |
| 15 | 13 | ||
| 16 | - | ||
| 14 | + | For example: | |
| 15 | + | ``` | |
| 17 | 16 | procedure proc0; | |
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 17 | + | var | |
| 18 | + | a, b: integer; | |
| 19 | + | begin | |
| 20 | + | … | |
| 21 | + | end; | |
| 23 | 22 | ``` | |
| 24 | 23 | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 24 | + | 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. | |
| 28 | 25 | ||
| 29 | - | ||
| 26 | + | 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): | |
| 27 | + | ``` | |
| 30 | 28 | program proc1; | |
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 29 | + | var | |
| 30 | + | SL: TStrings; | |
| 31 | + | begin | |
| 32 | + | SL := TStringlist.create; | |
| 33 | + | try | |
| 34 | + | … | |
| 35 | + | finally | |
| 36 | + | SL.free; | |
| 37 | + | end; | |
| 38 | + | end. | |
| 41 | 39 | ``` | |
| 42 | 40 | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - | ||
| 41 | + | `end` is used to indicate the end of the unit: | |
| 64 | 42 | ``` | |
| 65 | - | ||
| 66 | - | ||
| 43 | + | unit detent; | |
| 44 | + | uses math; | |
| 45 | + | ||
| 46 | + | procedure delta(r:real); | |
| 47 | + | ||
| 48 | + | implementation | |
| 49 | + | ||
| 50 | + | procedure delta; | |
| 51 | + | begin | |
| 52 | + | ||
| 53 | + | ... | |
| 54 | + | ||
| 55 | + | end; | |
| 56 | + | ||
| 57 | + | ... | |
| 58 | + | (* Note: No corresponding '''begin''' statement *) | |
| 59 | + | ||
| 60 | + | end. | |
| 61 | + | ``` | |
| 67 | 62 | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 63 | + | It also closes a [[Record|record]]: | |
| 75 | 64 | ``` | |
| 65 | + | Type | |
| 66 | + | ExampleRecord = Record | |
| 67 | + | Values: array [1..200] of real; | |
| 68 | + | NumValues: Integer; { holds the actual number of points in the array } | |
| 69 | + | Average: Real { holds the average or mean of the values in the array } | |
| 70 | + | End; | |
| 71 | + | ``` | |
| 76 | 72 | ||
| 73 | + | ||
| 74 | + | **Keywords:** [[Begin|begin]] — [[Do|do]] — [[Else|else]] — end — [[For|for]] — [[If|if]] — [[Repeat|repeat]] — [[Then|then]] — [[Until|until]] — [[While|while]] | |
| 75 | + | ||
| 77 | 76 | --- | |
| 78 | - | ||
| 77 | + | *From the Free Pascal wiki, page "End", as the Internet Archive kept it on 2022-10-06. 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).* |
