Skip to content

9618 · 11.2

Constructs — common mistakes

Common exam mistakes on 9618 Constructs. Learn what loses marks, then practise the topic with Examiner’s Ink.

Exam tip 1

Always ensure your constructs are properly closed: IF needs ENDIF, WHILE needs ENDWHILE, CASE needs ENDCASE, and FOR needs NEXT. Forgetting these is a common way to lose marks. Also, use indentation in your exam answers. While not always required for marks, it makes your code vastly more readable for the examiner and helps you spot errors in your own logic, especially with nested constructs.

When should I use a `WHILE` loop versus a `REPEAT` loop?

Use a WHILE...DO loop when the loop body might not need to execute at all. The condition is checked at the start, so if it's initially false, the program skips the loop entirely. Use a REPEAT...UNTIL loop when the loop body must execute at least once. The condition is checked at the end. This makes it perfect for tasks like input validation, where you need to get input at least once before you can check if it's valid.

Can I always use `IF` statements instead of a `CASE` statement?

Yes, any CASE statement can be logically rewritten as a series of IF...THEN...ELSEIF statements. However, a CASE statement is often preferred for clarity and readability when you are checking a single variable against a list of discrete, constant values. It makes the code's intent clearer at a glance.

What's the difference in the condition between `WHILE` and `REPEAT` loops?

A WHILE loop continues while its condition is TRUE and stops when it becomes FALSE. A REPEAT loop continues executing and only stops until its condition becomes TRUE. This is a crucial difference to remember when formulating your loop termination conditions.