Fill in the blanksQuestion 1 · Recall
Loading…
By the end you can write pseudocode using sequence, selection (IF and CASE), and iteration (FOR, WHILE and REPEAT), and document algorithms in structured English.
Any algorithm, however big, can be built from just three constructs.
Enrichment (not examinable by name): this idea is called the structured programming theorem.
Here is a sequence in pseudocode. The arrow ← means "becomes". Total ← Price * 2 works out Price times 2 and stores the result in a variable called Total:
OUTPUT "Enter the price"
INPUT Price
Total ← Price * 2
OUTPUT Total
The lines run once each, from top to bottom, in the order they are written.
Each construct matches a shape in a flowchart. Nothing else, such as a jump to another line, is needed.
A flowchart draws an algorithm as boxes joined by arrows. Each shape has one job:
Selection asks a question and then picks one path. Here is the layout:
IF condition THEN
// statements
ELSE
// statements
ENDIF
ELSE is optional. Leave it out if there is nothing to do when the condition is FALSE.IF needs its own ENDIF.ELSE. Instead, put a new IF inside the ELSE, with its own ENDIF.CASE is for one variable compared with several fixed values:
CASE OF Choice
1 : statements
2 : statements
OTHERWISE : statements
ENDCASE
OTHERWISE runs when none of the values match. It is optional.CASE can also test a range of values, written low TO high. This version uses the same grade boundaries as the IF example below:
CASE OF Mark
70 TO 100 : Grade ← "A"
60 TO 69 : Grade ← "B"
50 TO 59 : Grade ← "C"
OTHERWISE : Grade ← "U"
ENDCASE
Worked example: Selection examples
Grade a mark: 70 or more is A, 60 or more is B, 50 or more is C, anything else is U