For each of the pseudocode algorithms shown below, tick the appropriate box to show whether they will loop infinitely or not - OCR - GCSE Computer Science - Question 6 - 2018 - Paper 1
Question 6
For each of the pseudocode algorithms shown below, tick the appropriate box to show whether they will loop infinitely or not.
1. x = 0
while True
print... show full transcript
Worked Solution & Example Answer:For each of the pseudocode algorithms shown below, tick the appropriate box to show whether they will loop infinitely or not - OCR - GCSE Computer Science - Question 6 - 2018 - Paper 1
Step 1
Will loop infinitely
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
x = 0
This will loop infinitely because the condition in 'while True' is always true.
Step 2
Will not loop infinitely
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
x = 0
This will not loop infinitely because the loop will terminate once x reaches 10.
x = 0
This will not loop infinitely because the value of x is incremented, allowing the loop to terminate once x reaches 10.
y = 5
This will not loop infinitely because the for loop will execute a fixed number of times (5) and then terminate.
Step 3
Using pseudocode, write an algorithm that will use a count-controlled loop to print out the numbers 1 to 10 in ascending order.
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
for i = 1 to 10
print i
next
This pseudocode uses a count-controlled loop that starts at 1 and goes up to 10, printing each number in ascending order.