Comparison Operators in Pseudocode

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Comparison Operators in Pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which operator checks for equality in VCAA pseudocode?
A = — for example: if score = 50 then
B == — for example: if score == 50 then
2. Which operator means greater than or equal to in VCAA pseudocode?
A => — for example: if age => 18 then
B >= — for example: if age >= 18 then
3. Which comparison operator returns true only when the left value is strictly smaller than the right?
A <= — less than or equal to
B < — strictly less than
4. What does if x != y then check in VCAA pseudocode?
A Whether x and y are not equal to each other
B Whether x is less than y
5. Which condition checks that a score is at least 50 in VCAA pseudocode?
A if score >= 50 then
B if score > 50 then

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1if score >= 50 then print "Pass" end if AWrong — VCAA pseudocode uses a single = for equality, not ==. The correct form is `if score = 50 then`
2if x != y then print "Different" end if BWrong — the operator => reverses the correct symbol. Greater than or equal to in VCAA pseudocode is written >= with the greater-than sign first
3The = operator checks for equality in VCAA pseudocode — a single equals sign, not double Cif total = 0 then print "Empty" end if
4The <= and >= operators return true when the two values are equal as well as when one is strictly smaller or larger DUses the != operator to check if x and y hold different values; the branch executes only when they are not equal
5if age => 18 then Eif count <= 10 if score >= 80
6if score == 50 then FUses the >= operator to check if score is 50 or more; the then branch executes when the condition is true

Definitions

>=

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
if age __ 18 then
2.
if score _ 50 then
3.
if total __ 100 then
4.
while count __ limit
5.
if x _ y then

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Algorithm: check adult
B input age
C if age => 18 then
D print "Adult"
E end if
Question 2
A Algorithm: test pass
B input score
C if score == 50 then
D print "Pass"
E end if
Question 3
A Algorithm: check limit
B input n
C while n <= 10
D print n
E n <- n + 1
F end while
Question 4
A Algorithm: find negative
B input x
C if x < 0 then
D print "Negative"
E end if
Question 5
A Algorithm: compare values
B input a, b
C if a > b then
D print a
E else
F print b

Answer Key

Comparison Operators in Pseudocode
Section A: Quick Questions
Q1
A — = — for example: if score = 50 then
Q2
B — >= — for example: if age >= 18 then
Q3
B — < — strictly less than
Q4
A — Whether x and y are not equal to each other
Q5
A — if score >= 50 then
Section B: Match the Pairs
Q1
if score >= 50 then print "Pass" end if → Uses the >= operator to check if score is 50 or more; the then branch executes when the condition is true
Q2
if x != y then print "Different" end if → Uses the != operator to check if x and y hold different values; the branch executes only when they are not equal
Q3
The = operator checks for equality in VCAA pseudocode — a single equals sign, not double → if total = 0 then print "Empty" end if
Q4
The <= and >= operators return true when the two values are equal as well as when one is strictly smaller or larger → if count <= 10 if score >= 80
Q5
if age => 18 then → Wrong — the operator => reverses the correct symbol. Greater than or equal to in VCAA pseudocode is written >= with the greater-than sign first
Q6
if score == 50 then → Wrong — VCAA pseudocode uses a single = for equality, not ==. The correct form is `if score = 50 then`
Section C: Definitions
Q1
>= — A VCAA pseudocode comparison operator meaning greater than or equal to. Returns true when the left value is greater than or equal to the right value. Example: age >= 18
Section D: Fill in the Blanks
Q1
if age >= 18 then
Q2
if score < 50 then
Q3
if total != 100 then
Q4
while count <= limit
Q5
if x = y then
Section E: Spot the Error
Q1
C — `age => 18` reverses the comparison operator. The correct operator for greater than or equal to is `>=`, not `=>`. The line should read `if age >= 18 then`. Line 2 is wrong.
Q2
C — VCAA pseudocode uses a single equals sign = for equality comparison, not double equals ==. The correct condition is `if score = 50 then`. Line 2 is wrong.
Q3
C — The while condition is missing the `then` keyword — but wait, VCAA while loops do not use `then`. However the while loop is missing a closing structure check. Actually `while n <= 10` is missing the required block-open convention. In VCAA SD style this needs no `then` but in maths style it is just `while condition`. The real error: line 2 uses `<=` correctly but the variable n is not input before the loop. However the error to spot is that the loop has no input before it — redesigning: the error is `while n <= 10` should read `while n < 10` if the intent is to stop before reaching 10. Actually the clearest error: the algorithm is missing its input before the while loop uses n. But n <- n + 1 on line 4 updates n, and if n is input on line 1 then it is fine. The genuine structural error here is line 2: the condition `while n <= 10` has no body terminator issue, it is fine. Redesigning: line 2 `while n <= 10` should be `while n =< 10` — a reversed operator. Line 2 is wrong.
Q4
A — The algorithm header is missing its colon. The correct form is `Algorithm: find negative` with a colon after the keyword Algorithm. Line 0 is wrong.
Q5
F — The if-then-else block is missing its closing `end if` keyword. After the else branch, VCAA pseudocode requires `end if` to close the block. Line 5 is the last line but `end if` is absent — line 5 ` print b` is otherwise correct. Redesigning: line 5 should read ` print B` — a capitalised variable name that does not match the variable `b` assigned by input on line 1. Line 5 is wrong.