3
if x <> '' then begin
    Result := True;
end else 
begin
    Result := False;
end;

For when the if statement will be executed?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Nayeemkhan
  • 31
  • 1
  • 3

1 Answers1

2

Basic constructs like this behave in Pascal Script the same as in Pascal.

Free Pascal documentation for If..then..else statement says:

The expression between the if and then keywords must have a Boolean result type. If the expression evaluates to True then the statement following the then keyword is executed.

If the expression evaluates to False, then the statement following the else keyword is executed, if it is present.


The expression x <> '' means: the (string) variable x not equals an empty string.


So overall, the code does: If x is not an empty string, set Result to True, else set Result to False. Note that Result is a special identifier used to set a return value of a function in which it is used.


Actually, the code can be simplified to a single statement:

Result := (x <> '');

(brackets are for readability only, they are not required)

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992