91热爆

Reference Language examples

A range of examples are used to exemplify the structure of Reference Language.

Declaring and initialising a variable

DECLARE score INITIALLY 0

This means that a variable called score has been declared (created) and its initial value has been set to 0.

It is also possible to declare and initialise the values of an array.

DECLARE allLengths INITIALLY [ 10.1, 21.2, 11.3, 9.4, 19.8, 26.5, 9.3, 14.2, 28.2, 2.6, 12.6 ]

Initialising the value of a variable is an important element of programming. When declaring a variable in Reference Language, it is always necessary to initialise the value.

It may also be necessary to provide the data type when initialising, particularly if the type cannot be clearly spotted from the context. The examples shown above may also be stated as:

DECLARE score AS INTEGER INITIALLY 0
DECLARE allLengths AS ARRAY OF REAL INITIALLY [ 10.1, 21.2, 11.3, 9.4, 19.8, 26.5, 9.3, 14.2, 28.2, 2.6, 12.6 ]

Using the form shown above there is no ambiguity about the data type being used.

It is also possible to initialise an array using the following:

DECLARE sampleArray AS ARRAY OF INTEGER INITIALLY [ 0 ] * 10

This would create an array variable called sampleArray and would set the value as 0 for all ten elements in the array, without the need for individual initialisation of each element.

Assigning a value to a variable

SET score TO score + 1

In this case the value of the variable score is set to the current value of score plus one.

SET city TO 鈥淕lasgow鈥

When assigning a string value it is necessary to include inverted commas/speech marks as shown.

Assigning values to an Array

SET cities TO [鈥淕lasgow鈥, 鈥淓dinburgh鈥, 鈥淒undee鈥, 鈥淪tirling鈥, 鈥淧erth鈥, 鈥淚nverness鈥, 鈥淎berdeen鈥漖

The values shown within the square brackets would populate the array called cities.

Receiving User Input from a device

RECEIVE score FROM (INTEGER) KEYBOARD

This would receive a score from the user and store the score that they enter via the keyboard as an integer.

RECEIVE firstName FROM (STRING) KEYBOARD

This would receive a first name from the user and store the first name that they enter via the keyboard as string data.

RECEIVE initial FROM (CHARACTER) KEYBOARD

This would receive an initial (single letter) from the user and store the initial that they enter via the keyboard as a single character.

Sending Output to the display

SEND score TO DISPLAY

This would send the value held within the score variable to the screen, so if score held the number 21 the screen would show the number 21.

SEND 鈥淧lease try again!鈥 TO DISPLAY

This would display on screen as:

Please try again!