Difference between revisions of "Block"
From Lazarus wiki
Jump to navigationJump to search (create) |
(smooth wording; key feature scope) |
||
Line 3: | Line 3: | ||
The declarations are optional. | The declarations are optional. | ||
The sequence of statements can be empty, but at least the [[Begin|<syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight>]]…[[End|<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>]]-frame has to be present. | The sequence of statements can be empty, but at least the [[Begin|<syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight>]]…[[End|<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>]]-frame has to be present. | ||
+ | The key feature of a block is, that declarations are only valid while the statements are processed. | ||
+ | This concept is known as [[Scope|scope]]. | ||
+ | == example == | ||
The following is a valid block: | The following is a valid block: | ||
<syntaxhighlight lang="pascal"> | <syntaxhighlight lang="pascal"> | ||
Line 16: | Line 19: | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | An indication, whether something constitutes a block, is, whether you can use as part of a routine definition, as well as make a [[Program|<syntaxhighlight lang="pascal" enclose="none">program</syntaxhighlight>]] out of it (syntactically; | + | An indication, whether something constitutes a block, is, whether you can use as part of a routine definition, as well as make a [[Program|<syntaxhighlight lang="pascal" enclose="none">program</syntaxhighlight>]] out of it (syntactically; apart from the terminating dot). |
Revision as of 22:12, 29 November 2018
Template:Translate
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 has to be present.
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 as part of a routine definition, as well as make a program
out of it (syntactically; apart from the terminating dot).