Exam-style question
Try this first
Consider the following pseudocode: `count = 0` `data = [10, 20, 5, 30]` `FOR each item in data DO` `IF item > 15 THEN` `count = count + 1` `END IF` `END FOR` `OUTPUT count` What value will be outputted?.
- A.0
- B.1
- C.2
- D.3
Answer and explanation
Concise answer
2
Why this is correct
Initially, `count` = 0. For `item` = 10 (not > 15), `count` remains 0. For `item` = 20 (> 15), `count` becomes 1. For `item` = 5 (not > 15), `count` remains 1. For `item` = 30 (> 15), `count` becomes 2. Finally, 2 is outputted.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
