Operators Used in Pseudocode Assignment Statements
Operators Used in Pseudocode Assignment Statements
Logic Statements
Selection construct uses a condition to follow either first group of steps or second group of steps.
Condition consists of at least one logic proposition.
Person is classed as child if they are under 13 and adult if they are over 19. If they are between 13 and
19 inclusive they are classed as teenagers. We can write these statements as logic statements:
Example: It will help to recognize control structures of unknown language and also will help them learn a
new computer language.
CS- P2 Page 1
Features that make pseudocode or program easier to read and understand:
✓ Capitalization of Keywords
✓ Use of constants
✓ Use of Indentation
✓ Add comments
Comments are used in program or pseudocode to improve its readability. Comments are not compiled
(translated) therefore not executed, rather they help programmer in understanding code. Comments are
preceded by two forward slashes // in pseudo-code.
Stepwise Refinement
Many problems that we want to solve are complex. To make it easier to solve a complex problem, we
break the problem down into smaller steps. These might need breaking down further until the steps are
small enough to solve easily. This process of breaking down is known as stepwise refinement.
Types of Variable
Local variable: a variable that is accessible only within the module in which it is declared. Good design
uses local variables as it makes modules independent and re-usable.
Temp←NUM1
NUM1←NUM2
NUM2←Temp
CS- P2 Page 2
9.2.3 Writing pseudocode from a structured English
description
There are no set rules for writing structured English – the wording just needs to be unambiguous
and easily understandable. Pseudocode is more precise and usually follows an agreed set of rules.
• Any variables that need to be used can be identified and put in an identifier table – these can be
• Input and output can be identified from the wording used, for example, Enter, Read, Print,
Write.
• Selection can be identified from the wording used, for example, If, Then, Choose.
• Any iteration required can be identified from the wording used, for example, Loop, Repeat.
• Any processes needed can be identified from the wording used, for example, Set, Calculate.
When the identifier table is complete, each structured English statement can be used to write one
or more pseudocode statements, keeping the same order as the structured English.
structured English.
This can be used to identify the variables required and complete the identifier table (Table 9.3).
CS- P2 Page 3
Table 9.3 Using these identifiers, each step of the structured English algorithm can be converted to
There are three variables used: MarathonHours, MarathonMinutes and MarathonSeconds. This is
explicitly input and implicitly output as the user needs to understand what input is required. The
follows.
CS- P2 Page 4
ACTIVITY 9G
The structured English description has been extended below to check the runner’s time against
5 If marathon time in seconds is shorter than the personal best time then
Extend the identifier table and write the extra pseudocode to complete the algorithm. Then check your
algorithm works by writing a short program from your pseudocode statements
Flowcharts are diagrams showing the structure of an algorithm using an agreed set of symbols, as
CS- P2 Page 5
Table 9.4
Flowcharts can be used to identify any variables required and you can then complete an identifier
table. Each flowchart symbol can be used to identify and write one or more pseudocode
statements.
Here is an example of a flowchart of an algorithm that can be used to check an exam grade:
CS- P2 Page 6
Figure 9.4
The same algorithm is presented in pseudocode on the left. Below is the identifier table:
CS- P2 Page 7
9.2.5 Stepwise refinement
The algorithms looked at so far have been short and simple. When an algorithm is written to
solve a more complex problem, decomposition is used to break the problem down into smaller
and more manageable parts. These parts then need to be written as a series of steps where each
step can be written as a statement in a high-level programming language, this process is called
stepwise refinement.
Many problems are more complex than they seem if a robust solution is to be developed. Look at
CS- P2 Page 8
1 Enter time taken to run marathon in hours, minutes and seconds
ACTIVITY 9H
The flowchart on page 232 has been extended to allow more than one mark to be input.
CS- P2 Page 9
check your algorithm works by writing a short program from your pseudocode statements
1.1.3 Reject if out of range or not a whole number and re-input value step 1.1.1
CS- P2 Page 10
1.2.1 Input value for minutes
1.2.3 Reject if out of range or not a whole number and re-input value step 1.2.1
1.3.3 Reject if out of range or not a whole number and re-input value step 1.3.1
These steps can now be written in pseudocode. For example, the input routine for the seconds:
ACTIVITY 9I
Look at the algorithm to calculate the area of a chosen shape written in structured English
below. Use stepwise refinement to break each step into more manageable parts then rewrite the
Then check your pseudocode algorithm works by writing a short program from your
CS- P2 Page 11
pseudocode required is as follows. Selection / Conditional / Decision Statements
CS- P2 Page 12