Statements are the meat and bone of your application – they are the actual code that executes and determines application flow and logic. Without statements, an Oxygene application would not be able to do anything.
Statements can be standalone individual lines of code (such as a variable declaration with the
var keyword), include a sub-statement (such as
exit statements or
async expressions), or they can be so-called block statements and contain a whole nested block (such as the
end block statement or the
until block loop statement.
Aside from statements provided via Oxygene language constructs, Method Calls are probably the most commonly used type of statement (technically, expression) in an object oriented language such as Oxygene.
Please refer to the nested topics listed in the sidebar on the left for a complete reference of available statement types.
As a result, expressions can usually be used in the same way a regular statement is (and causing the expression's value to be ignored), but they can also be used in many other places where a value is expected — for example as parameters to method calls, or as parts of more complex expressions.
var x := CalculateValueA() + CalculateValueB(); // each method call is an expression, // as is the + operation of the two results CalculateValueB(); // result of the method call will be ignored // here expression is treated as a plain statement
Separating Individual Statements
In Pascal, individual statements within a method or nested in a block statement are separated by semicolons (
;). This means that (different from C#, Java or Objective-C, where statements are terminated with a semicolon), no semicolon is needed after the last statement or after a single statement. However, for convenience and consistency, it is common practice and recommended in Oxygene to provide a closing semicolon, even if not strictly required.
begin DoSomething(); DoSomethingElse(); // this last semicolon is not strictly needed end;
begin/end Block Statements
In any place where an individual statement is expected, the
end block statement can be used to wrap a whole bunch of separate statements together and treat them as a single statement.
For example, the
then statement expects a single sub-statement after the
then keyword, which will be executed if the condition preceding it evaluates to true. But it can easily be extended to conditionally execute a whole list of statements, when combined with
end. Technically speaking, the
end is not part of the
then statement's syntax.
if x ≥ 0 then DoSomething; // if expects only a single sub-statement... if x ≥ 0 then begin // ...but a begin/end statement can be used for that single DoSomething; // statement, allowing to conditionally execute a whole list DoSomethingElse; end;