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 鈥淧lease 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 鈥淧lease enter a valid height鈥 TO DISPLAY
RECEIVE height FROM (REAL) KEYBOARD
END WHILE
Although the sentence in English uses the term 鈥業f鈥, 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.