Exam-style question
Try this first
A loop runs 3 times. In each iteration, a variable `total` (initially 0) is updated by adding the iteration number (starting from 1). What is the final value of `total`?.
- A.3
- B.4
- C.6
- D.9
Answer and explanation
Concise answer
6
Why this is correct
Initially, `total` = 0. Iteration 1: `total` = 0 + 1 = 1. Iteration 2: `total` = 1 + 2 = 3. Iteration 3: `total` = 3 + 3 = 6. The loop finishes, and the final value of `total` is 6.
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.
