Difference between revisions of "Block"

From Lazarus wiki
Jump to navigationJump to search
(asm, block comment)
m (Fix typo)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Translate}}
+
{{LanguageBar}}
A '''block''' is a sequence of [[Declaration|declarations]] followed by a sequence of [[Statement|statements]].
+
 
 +
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|<syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight>]]…[[End|<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>]]-frame has to be present (in [[Routine|routines]] [[Asm|<syntaxhighlight lang="pascal" enclose="none">asm</syntaxhighlight>]]…<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight> is allowed, too).
+
The sequence of statements can be empty, but at least the [[Begin|<syntaxhighlight lang="pascal" inline>begin</syntaxhighlight>]]…[[End|<syntaxhighlight lang="pascal" inline>end</syntaxhighlight>]]-[[Frame|frame]] has to be present (in [[Routine|routines]] [[Asm|<syntaxhighlight lang="pascal" inline>asm</syntaxhighlight>]]…<syntaxhighlight lang="pascal" inline>end</syntaxhighlight> 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]].
  
== example ==
+
== Example ==
 +
 
 
The following is a valid block:
 
The following is a valid block:
 +
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
const
 
const
Line 19: Line 22:
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
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|<syntaxhighlight lang="pascal" enclose="none">program</syntaxhighlight>]] out of it (syntactically; apart from the terminating dot).
 
  
== see also ==
+
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|<syntaxhighlight lang="pascal" inline>program</syntaxhighlight>]] out of it (syntactically; apart from the terminating dot).
 +
 
 +
== See also ==
 
* [[Comments#block comments|block comments]]
 
* [[Comments#block comments|block comments]]
 +
 +
[[Category:Code]]
 +
[[Category:Pascal]]

Latest revision as of 11:16, 6 February 2021

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 beginend-frame has to be present (in routines asmend 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 out of it (syntactically; apart from the terminating dot).

See also