Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Constructs

EasyMedium
1234567891011121314
Question 11

A smart sensor records the water level variations of a river relative to its baseline (in centimeters) every hour over an 8-hour monitoring window.

  • A value of 0 is recorded if the water is exactly at baseline level.
  • A negative value is recorded if the water level is below baseline.
  • A positive value is recorded if the water level is above baseline.

The algorithm in Figure 1 has been created to count and output how many times the river level exceeded a specific threshold.

Figure 1

SET levels TO [12, -4, 0, 8, -2, 15, 30, -1]
SET warning_count TO 0
SET index TO 0

WHILE index < LENGTH(levels) DO
    IF levels[index] > 10 THEN
        SET warning_count TO warning_count + 1
    END IF
    SET index TO index + 1
END WHILE

SEND "High levels recorded: " & warning_count TO DISPLAY

Identify the type of iteration construct used in Figure 1.

Post-conditioned loop

Count-controlled loop

Infinite loop

Pre-conditioned loop

Constructs Questions

  1. IGCSE
  2. /Computer Science
  3. /Constructs