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, elseif and switch belong to?

Selection.

Which construct do the keywords for, while and do...until belong 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 while loop and a do...until loop?

A while loop checks the condition before the loop, so may run zero times; do...until checks after, so always runs at least once.

In OCR Exam Reference Language, how do you write a switch/case statement?

e.g. act on the value of choice being 1, 2 or anything else

switch choice: then case 1: … case 2: … default: … then endswitch

True or false? A for loop 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/case statement more limited than if/elseif?

switch only compares the value of one variable against a list of possible values. if/elseif can test any conditions, e.g. ranges such as mark >= 70.

In a switch statement, when does the default case run?

When the variable matches none of the case values. It is written as the last case, just before endswitch.

When does a while loop, and when does a do...until loop, become an infinite loop?

A while loop never ends if its condition is always true. A do...until loop never ends if its condition is never true.