Begin....End
The statement Begin...End uses the keywords Begin and End to create an enclosure that contains a block of statements.
Using Begin….End, allows the statements defined within the keyword enclosure to be viewed and treated as if they were a single statement, allowing the statements to become the body of a function or procedure and all executed together.
There is no limit to the number of statements that can be contained within the Begin….End enclosure block.
Comments can be included within the Begin...End statement block.
The following is an example of a simple Begin...End statement that also contains a comment line that will not be executed.
procedure
ScriptEvent (
var
Value : variant);
begin
// This is a simple block enclosure containing 2 statements
Value :=
71
LogInfo(
'The Value has been manually set to 71'
);
end
;
Normally the If statement only allows one statement to be executed if the result of the If statement is True.
So that when the If statement is used within a Begin….End statement, only the first line following the If will be executed as a part of the If statement. For more information on the If statement, please review If (If....Then/If....Else).
So in this following example, the line Hello campers! will display only when the condition on the If statement is True, and the second line What’s new pussycat? will display regardless of the result.
procedure
ScriptEvent (
var
Value : variant);
begin
if
Value>
10
then
LogInfo(
'Hello there campers!'
);
LogInfo(
'What'
s new pussycat?');
end
;
To have both lines display only when the condition on the If statement condition is met and is True, then it will be necessary to use a nested Begin….End statement to contain the required statements and have then execute together, as illustrated below.
In this example, the lines Hello campers! and What’s new pussycat? will display when the condition in the If statement is True.
procedure
ScriptEvent (
var
Value : variant);
begin
if
Value>
10
then
begin
LogInfo(
'Hello there campers!'
);
LogInfo(
'What'
s new pussycat?);
end
;
end
;
Please refer to Begin....End for another form for creating blocks of statements. However, the difference between Begin….End and Try….Except is that Try,,,,Except supports error handling.