Branching

Prior | Next

IF Statement
An if statement enables you to determine whether certain conditions are met before executing a particular block of code. Example:

  if x = 14 then DoSomething;

The test is evaluated, and if the condition is true the statement following the then is executed. If you have an if statement that makes multiple comparisons, make sure you enclose each set of comparisons in parentheses for code clarity. Example:

  if (x = 14) and (y = 7) then DoSomething;

You can combine multiple conditions using the else construct for the false condition. Example:

  if x = 14 then DoSomething else DoSomethingElse;

Procedures and Functions
A procedure is a program building block that performs some particular task when it is called and then returns to the calling part of your script. A function works the same except that a function returns a value after its exit to the calling part of the program. A procedure uses the following structure:

procedure ProcName(parameter list);
var
  {declare variables here}
begin
  {statements go here}
end;

A function uses the following structure:

function FuncName(parameter list) : ReturnType;
var
  {declare variables here}
begin
  {statements go here}
  Result := SomeValueToReturn;
end;

The local variable Result deserves special attention.  Every function has an implicit local variable called Result that contains the return value of the function.  Result will be a variable whose type is defined by the ReturnType in the function definition.  Procedures and functions are executed by using their name as a statement in your script.

Prior | Next