Programming Constructs Flashcards
Card 1 of 10
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.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.How is a
switch/casestatement more limited thanif/elseif?switchonly compares the value of one variable against a list of possible values.if/elseifcan test any conditions, e.g. ranges such asmark >= 70.In a
switchstatement, when does thedefaultcase run?When the variable matches none of the
casevalues. It is written as the last case, just beforeendswitch.When does a
whileloop, and when does ado...untilloop, become an infinite loop?A
whileloop never ends if its condition is always true. Ado...untilloop never ends if its condition is never true.