Statements

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 are usually written in Methods and other method-like members (such as Constructors or Finalizers), which provide a body that contain zero, one or more statements.

Statements can be standalone individual lines of code (such as a variable declaration with the var keyword), include a sub-statement (such as for loops, exit statements or async expressions), or they can be so-called block statements and contain a whole nested block (such as the begin/end block statement or the repeat/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.

Expressions

Expressions, covered separately in their own section here, are a special sub-type of statement that represent a value.

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 begin/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 if/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 begin/end. Technically speaking, the begin/end is not part of the if/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;

This same principle applies anywhere a statement is allowed, for example as sub-statement to for and while loops.

You can read more about begin/end block statements here.

All Statements

Declaration Statements

Expressions that can be Used as Statements