nums ← [4,7,2,9,1] — 0-indexed in OCR. Access: nums[0] = 4. Length: len(nums).| i | total | Output |
|---|---|---|
| start | 0 | |
| 1 | 1 | |
| 2 | 3 | |
| 3 | 6 | |
| 4 | 10 | 10 |
endif, wrong operator. In pseudo-code, using = for assignment instead of ← could be flagged.> instead of >=, off-by-one errors, wrong formula. Hardest to detect — must be found by testing.to 4 (runs 4 times: 1,2,3,4) with to 3 (runs 3 times). In OCR H446 pseudo-code, for i ← 1 to n is inclusive of both ends. Get this wrong in a trace and all subsequent values will be incorrect.