Reference languageReference language example

It is important to read and understand a formal language. Declaring variables and data types, using selection statements, iteration and using operators are comprehensions required before coding.

Part ofComputing ScienceSoftware design and development

Reference language example

This is an example of taking a problem statement and converting it into standardised reference language.

There is scope for an intermediary step where pseudocode is created first. Teachers and pupils will have their own understanding of pseudocode which can be applied to this scenario if necessary.

Statement in English

Ask the user to enter a length. If the user enters a length that is less than zero but greater than one hundred then ask the user to re-enter the length.

Reference language

DECLARE length AS REAL INITIALLY 0
RECEIVE length FROM (REAL) KEYBOARD
IF length < 0 OR length > 100 THEN
SEND “Please enter a valid length” TO DISPLAY
RECEIVE length FROM (REAL) KEYBOARD
END IF

Different programmers may interpret the same problem in a number of ways. The statement shown in English does not state that the program should continue to ask for a length until it is valid.

However, a programmer could interpret the sentence to mean this and may design the following section of reference language instead of the version shown above.

Statement in English

Ask the user to enter a height. If the user enters a height that is less than zero but greater than one hundred then ask the user to re-enter the height.

Reference language

DECLARE height AS REAL INITIALLY 0
RECEIVE height FROM (REAL) KEYBOARD
WHILE height < 0 OR height > 100 DO
SEND “Please enter a valid height” TO DISPLAY
RECEIVE height FROM (REAL) KEYBOARD
END WHILE

Although the sentence in English uses the term ‘If’, a programmer could choose to omit an IF statement in favour of a more efficient conditional loop that would always ask for the length until a valid number is entered. This is an example of applying problem solving and computational thinking when designing a solution.