0% found this document useful (0 votes)
15 views

Weekly Test 1 Solved

igcse

Uploaded by

bexey92753
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Weekly Test 1 Solved

igcse

Uploaded by

bexey92753
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. REPEAT... UNTIL and WHILE ... DO ...

ENDWHILE are two different loop structures you can use


when writing pseudocode.

Explain, using examples, why you would choose to use each type of loop.

Example 1 -
REPEAT
input age
UNTIL age >= 0

Reason for choice - This code ensures that age is entered at least once, it will continue
prompting until a value is entered. It also ensures that the age is valid, as in, it is a positive
value.

Example 2 –
Counter ← 10
WHILE Counter > 0
Print “*”
Counter = Counter - 1
ENDWHILE

Reason for choice – The loop ensures that * is printed 10 times and only when the counter
remains positive and it should not run if the condition is initially false.

2. Read this section of code that inputs the ages of people entering an event. The input
sequence is ended by inputting a negative value for age. The code outputs the number of
people at the event over the age of 18.

01 Num18 = 0
02 INPUT Age
03 WHILE Age >= 0 DO
04 IF Age >= 18 THEN
05 Num18 = Num18 + Age
06 ENDIF
07 ENDWHILE
08 PRINT Num18 – Age

There are four errors in this code.

Locate these errors and suggest code correction to remove each error. [4]

Error 1 - Line 04 IF Age >= 18

Correction - IF Age > 18

Error 2 – Line 05 Num18 = Num18 + Age

Correction - Num18 = Num18 + 1

Error 3 – Line 08 PRINT Num18 – Age

Correction - PRINT Num18

Error 4 -

Correction -

You might also like