Difference between revisions of "Block"
From Free Pascal wiki
Jump to navigationJump to search (clean wording a bit) |
|||
Line 3: | Line 3: | ||
A '''block''' is a sequence of [[Declaration|declarations]] followed by a sequence of [[statement]]s. | A '''block''' is a sequence of [[Declaration|declarations]] followed by a sequence of [[statement]]s. | ||
The declarations are optional. | The declarations are optional. | ||
− | The sequence of statements can be empty, but at least the [[Begin|{{HL|begin}}]]…[[End|{{HL|end}}]]-frame (or [[ | + | The sequence of statements can be empty, but at least the [[Begin|{{HL|begin}}]]…[[End|{{HL|end}}]]-frame (or [[Repeat|{{HL|repeat}}]]…[[Until|{{HL|until}}]]-frame) has to be present (in [[Routine|routines]] [[Asm|{{HL|>asm<}}]]…{{HL|end}} is allowed, too). |
The key feature of a block is, that declarations are only valid while the statements are processed. | The key feature of a block is, that declarations are only valid while the statements are processed. | ||
This concept is known as [[Scope|scope]]. | This concept is known as [[Scope|scope]]. |
Revision as of 00:09, 15 October 2020
│ English (en) │
A block is a sequence of declarations followed by a sequence of statements.
The declarations are optional.
The sequence of statements can be empty, but at least the begin
…end
-frame (or repeat
…until
-frame) has to be present (in routines >asm<
…end
is allowed, too).
The key feature of a block is, that declarations are only valid while the statements are processed.
This concept is known as scope.
Example
The following is a valid block:
const
foobar = -1;
type
booleanArray = array of boolean;
var
check: booleanArray;
begin
check := booleanArray.create(true, false, true);
end;
An indication, whether something constitutes a block, is, whether you can use it as part of a routine definition, as well as make a [[Program|program
] out of it (syntactically; apart from the terminating dot).