The three building blocks of every program — in OCR ERL and Python
IF / ELSEIF / ELSE / ENDIF and SWITCH / CASE in OCR ERL — and know the Python equivalentsFOR, WHILE and DO...UNTIL — knowing when to choose each onerange() off-by-one, DO...UNTIL exit condition direction, and infinite loopsELSEIF (one word, no colon) and ends with ENDIF. Python uses elif with a colon and indentation — never write ELSEIF in Python.if / elif chains — there is no SWITCH keyword. In Python 3.10+ match/case exists, but the OCR exam only expects if/elif.DEFAULT case in SWITCH to handle unexpected values — just like else in Python. The OCR mark scheme will look for it.FOR i = 1 TO 5 gives 1,2,3,4,5. Python range(1, 5) gives 1,2,3,4 only — the end is excluded. You need range(1, 6).| Feature | WHILE | DO...UNTIL |
|---|---|---|
| Test position | Pre-test (before body) | Post-test (after body) |
| Min iterations | 0 | 1 |
| Exits when... | Condition False | Condition True |
| Situation | Use |
|---|---|
| Repeat 10 times exactly | FOR |
| Keep going while valid | WHILE |
| Get input then validate | DO...UNTIL |
| Branch on a score range | IF/ELSEIF |
total ← 0 before the loopNEXT i at the end of the FOR loop= instead of ← for assignment| Loop | Use when | Min runs |
|---|---|---|
| FOR | Known count | 1 |
| WHILE | Unknown, may skip | 0 |
| DO..UNTIL | Must run once first | 1 |
range(1, 5) expecting 1,2,3,4,5 — but range() excludes the upper bound, giving 1,2,3,4range(1, 6) to get 1,2,3,4,5 · ERL FOR i = 1 TO 5 includes 5UNTIL num < 1 OR num > 10 — this exits on invalid input, the opposite of what you wantUNTIL num >= 1 AND num <= 10IF/ELSEIF/ELSE/ENDIF for ranges; SWITCH/CASE/DEFAULT/ENDSWITCH for exact values; Python uses elif not ELSEIFFOR i = 1 TO n ... NEXT i; Python range() excludes the end — use range(1, n+1)Get the full resource pack at CSZone.co.uk