Difference between revisions of "Begin"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 1: Line 1:
The [[Keyword|keyword]] '''begin''' is used to indicate the start of the executable section of a [[Function|FUNCTION]], [[Method|method]] of an [[Object|OBJECT]], [[Procedure|PROCEDURE]], [[Program|PROGRAM]], [[property]] of an object, or is used to delineate the start of a [[block]] statement.  
+
The [[Keyword|keyword]] '''begin''' is used to indicate the start of the executable section of a [[Function|function]], [[Method|method]] of an [[Object|object]], [[Procedure|procedure]], [[Program|program]], [[property]] of an object, or is used to delineate the start of a [[block]] statement.  
  
For a function, method, procedure, program, or property, it is used after all [[Const|CONST]], [[TYPE]] and [[Var|VAR]] declarations, and before the first executable statement.  It is always terminated by an [[End|END]] statement:
+
For a function, method, procedure, program, or property, it is used after all [[Const|const]], [[Type|type]] and [[Var|var]] declarations, and before the first executable statement.  It is always terminated by an [[End|end]] statement:
  
   '''program''' Project1;
+
<delphi>
   '''var'''(..);
+
   program Project1;
   '''begin'''
+
   var (..);
 +
   begin
 
     (..);
 
     (..);
   '''end'''.
+
   end.
 +
</delphi>
  
For a block statement, it delineates the top of the block, and is also terminated by an END statement:
+
For a block statement, it delineates the top of the block, and is also terminated by an end statement:
  
   '''if''' (..)'''then'''
+
<delphi>
  '''begin'''
+
   if (..) then
    (..)
+
    begin
  '''end'''
+
      (..)
   '''else'''
+
    end
  '''begin'''
+
   else
    (..)
+
    begin
  '''end''';
+
      (..)
 +
    end;
 +
</delphi>
  
 
A '''begin''' ''must'' be closed with '''[[End|end]]'''.
 
A '''begin''' ''must'' be closed with '''[[End|end]]'''.
  
 
{{Keywords}}
 
{{Keywords}}

Revision as of 06:44, 17 October 2007

The keyword begin is used to indicate the start of the executable section of a function, method of an object, procedure, program, property of an object, or is used to delineate the start of a block statement.

For a function, method, procedure, program, or property, it is used after all const, type and var declarations, and before the first executable statement. It is always terminated by an end statement:

<delphi>

 program Project1;
 var (..);
 begin
   (..);
 end.

</delphi>

For a block statement, it delineates the top of the block, and is also terminated by an end statement:

<delphi>

 if (..) then
   begin
     (..)
   end
 else
   begin
     (..)
   end;

</delphi>

A begin must be closed with end.


Keywords: begindoelseendforifrepeatthenuntilwhile