Programming Constructs Flashcards
All 10 cards in this deck
Name the three basic programming constructs.
Sequence, selection (branching) and iteration.
Which construct do the keywords
if,elseifandswitchbelong to?Selection.
Which construct do the keywords
for,whileanddo...untilbelong to?Iteration.
What is the difference between count-controlled and condition-controlled iteration?
Count-controlled repeats a set number of times; condition-controlled repeats until/while a condition is met.
What is the difference between a
whileloop and ado...untilloop?A
whileloop checks the condition before the loop, so may run zero times;do...untilchecks after, so always runs at least once.What are the steps to write a selection statement with more than two outcomes in OCR Exam Reference Language?
e.g. grade A if score is 80+, B if 60+, otherwise C
- Test the first condition:
if score >= 80 then print("A") - Add further tests:
elseif score >= 60 then print("B") - Catch the rest and close:
else print("C")thenendif
- Test the first condition:
What are the steps to write a count-controlled loop in OCR Exam Reference Language?
e.g. print the numbers 1 to 5
- Set counter, start and end:
for i = 1 to 5 - Put the repeated code inside:
print(i) - Close the loop:
next i
- Set counter, start and end:
In OCR Exam Reference Language, how do you write a
switch/casestatement?e.g. act on the value of
choicebeing 1, 2 or anything elseswitch choice:thencase 1:…case 2:…default:… thenendswitchTrue or false? A
forloop can only count up in steps of 1.False. A step can be given, e.g.
for i = 0 to 10 step 2.What are the steps to write a
whileloop in OCR Exam Reference Language?
e.g. keep doublingtotal, which starts at 1, while it is under 50- Set the variable used in the condition before the loop:
total = 1 - Write
whileand the condition:while total < 50 - Write the code to repeat, then close with
endwhile:total = total * 2thenendwhile
- Set the variable used in the condition before the loop: