2.2.1(a), 1.2.3(c), 1.2.4(b) · Programming

Sequence, selection and iteration

The lesson for this topic

Question 11 mark

What does this program print?

total = 0for i = 2 to 8 step 3    total = total + inext iprint(total)
Question 21 mark

What does this program print?

n = 1count = 0while n < 100    n = n * 3    count = count + 1endwhileprint(count)
Question 31 mark

What does this program print?

x = 50do    x = x - 20until x < 0print(x)
Question 41 mark

How many lines does this program print?

for i = 1 to 3    for j = 1 to i        print(str(i) + str(j))    next jnext i
Question 51 mark

When should a while loop be used rather than a for loop?

Question 61 mark

How many times does this loop print x?

for k = 5 to 1    print("x")next k
Question 71 mark

What does this program print?

word = "level"rev = ""for i = word.length - 1 to 0 step -1    rev = rev + word.substring(i, 1)next iif rev == word then    print("yes")else    print("no")endif
Question 81 mark

What is iteration?

Structured question 110 marks

A number sequence

The program below builds a sequence of numbers.

a = 1b = 1for n = 1 to 4    c = a + b    a = b    b = cnext nprint(b)
(a) Complete4 marks

the trace table: one row for the end of each pass, then one row for the print.

nabcoutput
1122
(b) State1 mark

the value printed if the loop runs for n = 1 to 6.

(c) Explain2 marks

why the order of lines 5 and 6 matters.

0 words
(d) Write3 marks

a loop that prints every even number from 2 to 20.

Question 91 mark

What does this program print?

x = 0for i = 1 to 10    if i MOD 2 == 1 then        x = x + i    endifnext iprint(x)

Independent practice for OCR A-level Computer Science (H446), not endorsed by OCR.

Privacy · Terms