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 0RECEIVE length FROM (REAL) KEYBOARDIF length < 0 OR length > 100 THENSEND “Please enter a valid length” TO DISPLAYRECEIVE length FROM (REAL) KEYBOARDEND IFDifferent 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 0RECEIVE height FROM (REAL) KEYBOARDWHILE height < 0 OR height > 100 DOSEND “Please enter a valid height” TO DISPLAYRECEIVE height FROM (REAL) KEYBOARDEND WHILEAlthough 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.