Appendix: Labelled Statements

A labelled statement is a type of compound statement that is not executed unless it is explicitly referenced by a special function. A labelled statement can be referenced at any time, and as many times as needed, but only within the expression that contains it.

The syntax for a labelled statement is as follows:

#StatementLabel:

{

StatementContents;

}

The keyword after the hash (#) denotes the statement's unique name, or Label. When the associated label is referenced using a JumpTo statement, the contents inside the braces will be executed in full. When the labelled statement has finished processing, the main expression will continue after the point it was originally referenced.

JumpTo statements have the following syntax:

JumpTo:StatementLabel;

You can use a labelled statement to JumpTo itself if the situation calls for it. This will create a loop, so you must ensure that you include a means of terminating the loop or it will run indefinitely, causing your application to freeze or crash.

Labelled statements are also an important part of Error Handling procedures. They can be called using OnErrorJumpTo statements.

In situations where a statement may be needed more than once in a single expression, creating a re-useable statement is advisable over simply copying the statement multiple times throughout the expression.

The following shows an example of the latter method, where an expression is used to tally and analyse exam results:

PercentageTotal:= PercentageTotal + ( BiologyMarks / 150 * 100 );

TotalMarks:= TotalMarks + BiologyMarks;

ResultTally:= ResultTally + 1;

PercentageTotal:= PercentageTotal + ( MathsMarks / 150 * 100 );

TotalMarks:= TotalMarks + MathsMarks;

ResultTally:= ResultTally + 1;

PercentageTotal:= PercentageTotal + ( PhysicsMarks / 150 * 100 );

TotalMarks:= TotalMarks + PhysicsMarks;

ResultTally:= ResultTally + 1;

(...and so on for every subject taken by the student)

As you can see, there is a lot of repetition in this expression. Although the expression will do what it is supposed to do, if any part of the process changes, the expression block for each subject will need to be individually re-written.

A more compact and efficient version of this process is shown below:

#SubjectAnalysis:

{

PercentageTotal:= PercentageTotal + ( SubjectMarks / 150 * 100 );

TotalMarks:= TotalMarks + SubjectMarks;

ResultTally:= ResultTally + 1;

}

SubjectMarks:= BiologyMarks;

JumpTo:SubjectAnalysis;

SubjectMarks:= MathsMarks;

JumpTo:SubjectAnalysis;

SubjectMarks:= PhysicsMarks;

JumpTo:SubjectAnalysis;

(...and so on for every subject taken by the student)

Notice that all of the repeated calculations from the previous example are now defined as part of a single labelled statement located at the top of the expression. The parts of the expression that concern individual subjects are more concise, and rather than duplicating calculations each time, they simply reference the labelled statement.