Difference between revisions of "Begin"

From Lazarus wiki
Jump to navigationJump to search
(rewrite)
Line 1: Line 1:
 
{{Begin}}
 
{{Begin}}
  
The [[Reserved word|reserved word]] <syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight> is used to indicate the start of the executable section of a [[Function|<syntaxhighlight lang="pascal" enclose="none">function</syntaxhighlight>]], [[Method|method]] of an [[Object|<syntaxhighlight lang="pascal" enclose="none">object</syntaxhighlight>]], [[Procedure|<syntaxhighlight lang="pascal" enclose="none">procedure</syntaxhighlight>]], [[Program|<syntaxhighlight lang="pascal" enclose="none">program</syntaxhighlight>]], [[Property|<syntaxhighlight lang="pascal" enclose="none">property</syntaxhighlight>]] of an object, or is used to delineate the start of a [[Block|block]] [[statement]].  
+
The [[Reserved word|reserved word]] <syntaxhighlight lang="pascal" inline>begin</syntaxhighlight> marks the start of the definition of the executable portion of a [[Block|block]].
 +
In conjunction with [[End|<syntaxhighlight lang="pascal" inline>end</syntaxhighlight>]] it is also used to group [[statement]]s into a so-called “compound statement”.
  
For a <syntaxhighlight lang="pascal" enclose="none">function</syntaxhighlight>, method, <syntaxhighlight lang="pascal" enclose="none">procedure</syntaxhighlight>, <syntaxhighlight lang="pascal" enclose="none">program</syntaxhighlight>, or <syntaxhighlight lang="pascal" enclose="none">property</syntaxhighlight>, it is used after all [[Const|<syntaxhighlight lang="pascal" enclose="none">const</syntaxhighlight>]], [[Type|<syntaxhighlight lang="pascal" enclose="none">type</syntaxhighlight>]] and [[Var|<syntaxhighlight lang="pascal" enclose="none">var</syntaxhighlight>]] declarations, and before the first executable statement. It is always terminated by an [[End|<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>]] statement:
+
{{Note|In [[Pascal]] a compound statement does not create a new scope.
 +
Only blocks do.}}
  
<syntaxhighlight lang="pascal">
+
In [[Extended Pascal|extended Pascal]] <syntaxhighlight lang="pascal" inline>to begin do …</syntaxhighlight> starts the definition of the [[Initialization|<syntaxhighlight lang="pascal" inline>initialization</syntaxhighlight> part of a module]].
  program Project1;
 
  var (..);
 
  begin
 
    (..);
 
  end.
 
</syntaxhighlight>
 
  
For a block statement, it delineates the top of the block, and is also terminated by an <syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight> statement:
+
While every <syntaxhighlight lang="pascal" inline>begin</syntaxhighlight> must have a corresponding <syntaxhighlight lang="pascal" inline>end</syntaxhighlight>, not all occurrences of <syntaxhighlight lang="pascal" inline>end</syntaxhighlight> have a corresponding <syntaxhighlight lang="pascal" inline>begin</syntaxhighlight>.
  
<syntaxhighlight lang="pascal">
+
== syntax justification ==
  if (..) then
+
Lots of programming languages use a pair of single characters to indicate boundaries.
    begin
+
Typing out the words <syntaxhighlight lang="pascal" inline>begin</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>end</syntaxhighlight> is indeed more cumbersome than writing <syntaxhighlight lang="c" inline>{ }</syntaxhighlight>.
      (..)
+
However, the meaning of such characters is not as obvious as words are.
    end
 
  else
 
    begin
 
      (..)
 
    end;
 
</syntaxhighlight>
 
  
A <syntaxhighlight lang="pascal" enclose="none">begin</syntaxhighlight> ''must'' be closed with [[End|<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>]].
+
== matching ==
 +
The source editor of the [[Lazarus IDE]] supports a “find matching begin/end” function.
  
 
{{Keywords}}
 
{{Keywords}}

Revision as of 22:21, 19 October 2019

Deutsch (de) English (en) español (es) suomi (fi) français (fr) русский (ru) 中文(中国大陆)‎ (zh_CN)

The reserved word begin marks the start of the definition of the executable portion of a block. In conjunction with end it is also used to group statements into a so-called “compound statement”.

Note-icon.png

Note: In Pascal a compound statement does not create a new scope. Only blocks do.

In extended Pascal to begin do starts the definition of the initialization part of a module.

While every begin must have a corresponding end, not all occurrences of end have a corresponding begin.

syntax justification

Lots of programming languages use a pair of single characters to indicate boundaries. Typing out the words begin and end is indeed more cumbersome than writing { }. However, the meaning of such characters is not as obvious as words are.

matching

The source editor of the Lazarus IDE supports a “find matching begin/end” function.


Keywords: begindoelseendforifrepeatthenuntilwhile