Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Subject:
Topics:
Avg
score:
–
Topics
done:
0/32

Nested statements

Practise 24 exam-style questions on Nested statements for Cambridge IGCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with an AI tutor on hand if you get stuck.

  • 24 questions
  • 1–7 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

2 marks

Look at this pseudocode:

Count ← 0
FOR Row ← 1 TO 5
    FOR Column ← 1 TO Row
        Count ← Count + 1
    NEXT Column
NEXT Row
OUTPUT Count

State the output, and explain why it is not 25.

Model answer

15. The inner loop runs Row times, so it runs once, then twice, then 3, 4 and 5 times: 1 + 2 + 3 + 4 + 5 = 15.

Explanation

An inner loop can use the outer loop's counter in its own start or end value. Here the inner loop grows by one pass each time round the outer loop, so the total is a sum, not 5 × 5.

Mark scheme
  1. 1 mark

    15

  2. 1 mark

    The end value of the inner loop is Row, so the inner loop runs a different number of times on each pass of the outer loop (1 + 2 + 3 + 4 + 5), not 5 times every pass

Question 2

2 marks

The flowchart shows an algorithm that inputs a valid score from 0 to 10 from each of 5 judges, then outputs the total score.

State what should be written in decision A and in box B.

Flowchart, read from the top. START, then the process box "Total ← 0", then the process box "Judge ← 1", then the decision box "Judge ≤ 5?" (if Yes, the input/output box "INPUT Score", then decision box A (if No, the flow line goes back up to the input/output box "INPUT Score"; if Yes, the loop ends), then process box B, then the process box "Judge ← Judge + 1", then the flow line goes back up into the decision box "Judge ≤ 5?"; if No, the loop ends). After the loop: the input/output box "OUTPUT Total", then STOP.

Model answer

A: Score ≥ 0 AND Score ≤ 10?
B: Total ← Total + Score

Explanation

The post-condition loop inside the count-controlled loop repeats the input until it is valid, so decision A must be TRUE (Yes) for a valid score, which needs both comparisons joined by AND. Only after a valid score has been entered is it added to the total in box B.

Mark scheme
  1. 1 mark

    A: Score ≥ 0 AND Score ≤ 10?

    Accept Score >= 0 AND Score <= 10. Must use AND.

  2. 1 mark

    B: Total ← Total + Score

Question 3

3 marks

Look at this pseudocode:

FOR Start ← 1 TO 3
    Value ← Start
    Steps ← 0
    WHILE Value < 10 DO
        Value ← Value * 2
        Steps ← Steps + 1
    ENDWHILE
    OUTPUT Start, " ", Steps
NEXT Start

State the three lines of output.

Model answer

1 4
2 3
3 2

Explanation

For each value of Start, the WHILE loop doubles Value until it reaches 10 or more: 1 goes 2, 4, 8, 16 (4 steps), 2 goes 4, 8, 16 (3 steps) and 3 goes 6, 12 (2 steps). Value and Steps are reset at the start of each pass of the FOR loop, so each count starts from 0.

Mark scheme
  1. 1 mark

    1 4

  2. 1 mark

    2 3

  3. 1 mark

    3 2

Question 4

5 marks

A quiz has 10 players. Each player's score must be from 0 to 100.

Write pseudocode that inputs a score for each of the 10 players, repeating the input for a player until a valid score is entered. After all 10 scores have been entered, output how many players scored more than 75.

Model answer

HighScores ← 0
FOR Player ← 1 TO 10
    REPEAT
        INPUT Score
    UNTIL Score >= 0 AND Score <= 100
    IF Score > 75
      THEN
        HighScores ← HighScores + 1
    ENDIF
NEXT Player
OUTPUT "Players scoring over 75: ", HighScores

Explanation

The FOR loop makes sure exactly 10 valid scores are collected, while the nested REPEAT loop keeps asking for one player's score until it is valid. The IF is placed after the validation loop so only valid scores are checked, and the output comes after NEXT so it happens once.

Mark scheme
  1. 1 mark

    MP1 counter set to 0 before the loops

    max 5

  2. 1 mark

    MP2 count-controlled loop that repeats 10 times

  3. 1 mark

    MP3 validation loop (REPEAT or WHILE) nested inside the count-controlled loop, with the score input inside it

  4. 1 mark

    MP4 validation condition: Score >= 0 AND Score <= 100

    For a WHILE loop: Score < 0 OR Score > 100.

  5. 1 mark

    MP5 after validation, inside the outer loop, adds 1 to the counter if Score > 75

  6. 1 mark

    MP6 outputs the count after the outer loop

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

AI Tutor Hints first, answers after you try

Hi! Stuck? Ask me for a hint and I’ll help you work it out. Once you’ve checked your answer I can explain exactly where the marks are.