Programming constructs: sequence, iteration, branching.
2.2.1 Programming Techniques
Programming Techniques — Note 1 of 6
Candidates need to understand the constructs of sequence, iteration and branching, and use them independently and in combination to produce a solution. This includes IF (with ELSEIF and ELSE) and select case statements, and both condition-controlled (e.g. while, repeat until) and count-controlled (e.g. FOR) iteration. Candidates need to be able to read, create and trace code (for example using a trace table) that uses these constructs.
All programs are built from three constructs: sequence, iteration and branching (selection). You need to use them independently and in combination, and read, create and trace code that uses them.
Exam tipCommon mistake
Instructions executed one after another in order.
Choosing which code to run based on a condition, using if ... then ... elseif ... else ... endif or switch/case.
Repeating code. Count-controlled loops (for) repeat a set number of times; condition-controlled loops (while, do ... until) repeat until a condition changes.
while loop checks its condition BEFORE each iteration (it may run zero times); a do ... until loop checks AFTER (it always runs at least once).total = 0
for i = 1 to 5
mark = int(input("Enter mark: "))
if mark >= 0 AND mark <= 100 then
total = total + mark
else
print("Invalid mark")
endif
next i
do
answer = input("Continue? (y/n) ")
until answer == "y" OR answer == "n"
switch answer:
case "y":
print("Continuing")
default:
print("Goodbye")
endswitch