WACE exams start Wed 28 Oct — 18 days away

ATARMAxxing · WACE Computer Science revision notes

Control structures, data types, operators and Boolean logic

Programming skills and concepts
Programming · Unit 3 - Programming

What this note covers

  1. The three control structures and how the exam writes them
  2. Choosing between fixed, pre-test and post-test loops
  3. Data types and why the choice matters
  4. Arithmetic, relational and logical operators
  5. Complex logical expressions and order of precedence
  6. Worked example: tracing a loop that combines selection and iteration
  7. Exam technique for control-structure questions

7 sections · 10 key terms & formulas · 6 common mistakes

Free sample

1. The three control structures and how the exam writes them

Every algorithm you will write in this course is built from three control structures: sequence (statements run in order), selection (a condition decides which statements run) and iteration (statements repeat). The syllabus splits iteration into fixed (count-controlled), pre-test and post-test loops, and questions say whether they want Python or pseudocode. The support booklet conventions are guidance, not a strict syntax: capitalise keywords, indent the body of every structure, close each structure explicitly (END IF, END WHILE, END FOR) and use = for assignment and == for comparison.

StructurePseudocode (booklet style)Python
One-way selectionIF speed > 50 THEN … END IFif speed > 50:
Two-way selectionIF … ELSE … END IFif … else:
Multi-way selectionIF … ELSE IF … ELSE … END IF, or CASE value OF … END CASEif … elif … else:
Fixed loopFOR i = 1 TO 10 … END FORfor i in range(1, 11):
Pre-test loopWHILE condition … END WHILEwhile condition:
Post-test loopREPEAT … UNTIL conditionwhile True: … if condition: break

Two details cost marks every year. First, a CASE statement tests single values only; a range such as "speed between 20 and 50" must be written with IF. Second, Python's range stops one before its end value, so the pseudocode loop FOR i = 1 TO 10 becomes range(1, 11). Writing range(1, 10) gives nine iterations, which is a logic error a trace table would expose.

2. Choosing between fixed, pre-test and post-test loops

Pick the loop from what you know before the loop starts. Use a fixed loop when the number of repetitions is known (process every element of a list, print 12 monthly totals). Use a pre-test loop when the body might need to run zero times, because the condition is checked first (keep reading lines while the file has lines). Use a post-test loop when the body must run at least once, because the condition is checked after it; input validation is the classic case, since you cannot test a value you have not yet read.

Python has no REPEAT … UNTIL, so a post-test loop is written either with while True and a break, or, more commonly in marking keys, as a "priming read" followed by a pre-test loop. The version below reads once, then re-prompts while the value is outside 6 to 17. It was run with the inputs 4, 19 and 12:

age = int(input("Age: "))
while age < 6 or age > 17:
    print("Out of range - try again")
    age = int(input("Age: "))
print("Accepted:", age)

Output:

Out of range - try again
Out of range - try again
Accepted: 12

Notice the condition is the negation of the valid range: valid means age >= 6 AND age <= 17, so the loop continues while age < 6 OR age > 17. In pseudocode the post-test form reads REPEAT INPUT(age) UNTIL (age >= 6) AND (age <= 17): UNTIL takes the exit condition, WHILE takes the continue condition. Mixing the two up is the most common loop error in written answers.

3. Data types and why the choice matters

The four types in the syllabus are integer (whole numbers, used for counts and indices), float (numbers with a fractional part, used for measurements and averages), string (text, including digits that are never calculated with) and Boolean (True or False, used for flags and conditions). Choosing a type is a design decision you must justify: a phone number or postcode is a string because it may start with 0 and no arithmetic is done on it; a quantity in stock is an integer; a temperature reading is a float; "has paid" is a Boolean.

In Python, input() always returns a string, so numeric input must be converted with int() or float(). Adding two strings concatenates them rather than adding them. Floats are stored in binary and cannot represent most decimals exactly, so never compare floats with == after arithmetic; round first or compare with a tolerance. Each line below was executed:

print("7" + "3")
print(7 + 3)
print(int("7") + 3)
print(0.1 + 0.2 == 0.3)
print(round(0.1 + 0.2, 2) == 0.3)

Output:

73
10
10
False
True

An exam may ask you to "state the most appropriate data type and justify". A full answer names the type and gives a reason tied to the data: "Integer, because the number of seats is always a whole number and is used in calculations." One word without a reason usually earns only half the marks. Money is a special case: a float is acceptable in exam answers, but storing whole cents as an integer avoids rounding drift in totals, and saying so shows understanding.

4. Arithmetic, relational and logical operators

The syllabus lists arithmetic operators (+, -, *, /, %), relational operators (==, !=, >, <, >=, <=) and logical operators (AND, OR, NOT). Python adds // for integer (floor) division; the booklet also accepts DIV and MOD in pseudocode. Know exactly what each division operator produces:

ExpressionResultWhy
17 / 53.4true division always gives a float
17 // 53whole number of times 5 fits into 17
17 % 52remainder after taking out three 5s
4729 % 109last digit of a whole number
4729 // 10472removes the last digit
135 // 60 and 135 % 602 and 15135 minutes is 2 hours 15 minutes

The modulus operator turns up in many algorithms: n % 2 == 0 tests for an even number, i % 3 == 0 picks every third item, and // with % together split a quantity into larger and smaller units. Be careful with negative operands in Python: -7 // 2 is -4, because floor division rounds down towards negative infinity, not towards zero.

A relational operator compares two values and produces a Boolean. Writing = where you mean == is a syntax error in Python and an ambiguity in pseudocode that markers penalise. Logical operators combine Booleans: AND is true only when both sides are true, OR when at least one is, and NOT reverses a value.

5. Complex logical expressions and order of precedence

When an expression mixes operators, evaluate in this order: brackets, arithmetic, relational comparisons, then NOT, then AND, then OR. Because AND binds more tightly than OR, the two expressions below are different. Take age = 20, member = False, guest = False:

  • age >= 18 OR member AND guest → member AND guest is evaluated first (False), then True OR False gives True.
  • (age >= 18 OR member) AND guest → the bracket gives True, then True AND False gives False.

When a question asks you to "evaluate" an expression, show each step in this order and write the intermediate Boolean values; the marks are for the working as well as the final value. When you write a condition yourself, add brackets even when precedence would make them optional, because the marker should never have to guess what you meant.

De Morgan's laws let you rewrite a negated condition: NOT (A AND B) is equivalent to NOT A OR NOT B, and NOT (A OR B) is equivalent to NOT A AND NOT B. The truth table proves the first law row by row:

ABA AND BNOT (A AND B)NOT A OR NOT B
TrueTrueTrueFalseFalse
TrueFalseFalseTrueTrue
FalseTrueFalseTrueTrue
FalseFalseFalseTrueTrue

This is exactly what happens when you turn a "valid" test into a "keep asking" test: NOT (x < 1 OR x > 10) means the same as x >= 1 AND x <= 10. Checking the boundary values 0, 1, 10 and 11 confirms the two forms agree.

6. Worked example: tracing a loop that combines selection and iteration

Trace tables (desk checks) are examined directly, and they are also the fastest way to check your own code in the exam. Give each variable a column, add a column for any condition, and write a new row every time a value changes or the loop repeats. Here is a short program and its output when run:

readings = [12, 31, 7, 45, 28]
total = 0
count_high = 0
for r in readings:
    if r > 25:
        count_high = count_high + 1
    total = total + r
print(total, count_high, total / len(readings))

Output:

123 3 24.6

The trace table for the loop body, one row per iteration:

rr > 25count_hightotal
12False012
31True143
7False150
45True295
28True3123

Three readings exceed 25 (31, 45 and 28), the total is 123 and the mean is 123 / 5 = 24.6. Note that 25 itself would not be counted, because the test is strictly greater than. Questions often hide a boundary value like this in the data to see whether you trace the condition exactly rather than reading the intention of the code.

When a question gives you code and asks for its output, the marking key expects the exact output, including order and formatting. If a print statement sits inside the loop, there will be one line of output per iteration; if it is after the loop (as here), there is only one line. Indentation in Python decides which, so read it carefully.

7. Exam technique for control-structure questions

Marking keys for short algorithms award marks element by element: correct initialisation of accumulators and counters, a loop with the right start, end and update, a correctly formed condition, the correct processing inside the loop, and the required output or return. A response with one small slip still collects most marks if each element is visible, so write each element on its own line rather than compressing logic.

  • Check the command: "write in Python" needs valid Python syntax (colons, indentation, correct function names); "write an algorithm" accepts clear pseudocode.
  • Initialise every variable before the loop. An accumulator set to 0 inside the loop resets on every pass, which is a logic error.
  • Make sure every WHILE loop changes something its condition depends on, otherwise it never ends.
  • Test your loop at its boundaries: the first value, the last value, and a value exactly on any comparison threshold.

A model sentence for the commonly asked comparison: "A pre-test loop evaluates its condition before the body executes, so the body may execute zero times; a post-test loop evaluates its condition after the body, so the body always executes at least once, which suits input validation because a value must be read before it can be checked."

The 2025 examination report noted that candidates handled foundational structures such as initialisation, iteration and simple data processing better than multi-step algorithms. That makes the basics your safe marks: secure them first, then spend remaining time on the harder logic.

Included in the WACE Computer Science Mastery Pack

20 full-length practice exams with worked solutions, 20 revision notes, 64 practice questions and 200 flashcards.

Unlock Computer Science — $20

Preview a sample note and question free on the WACE Computer Science hub →

WACE Computer Science · revision note 1 of 20