Relational operators: = and <>

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

Relational operators: = and <>

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which condition checks whether Answer is equal to 5 in Cambridge pseudocode?
A IF Answer <- 5 THEN
B IF Answer = 5 THEN
2. Which line stores the value 5 in the variable Answer?
A Answer = 5
B Answer <- 5
3. Name has the value "Alex". What does Name <> "Sam" give?
A TRUE
B FALSE
4. Answer has the value 5. What does Answer <> 5 give?
A FALSE
B TRUE
5. Which symbol means 'is not equal to' in Cambridge pseudocode?
A <>
B !=

Match the Pairs

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

Left columnRight column
1Answer = 5 A<- is assignment, not a comparison. A condition should use = to test equality: IF Score = 10 THEN
2Name <> "Sam" BTests whether Answer is equal to 5 and gives TRUE or FALSE
3Use <- (not =) when you want to store a value in a variable CIF Colour = "red" THEN
4Use = inside an IF condition to check whether text matches exactly DTests whether Name is not equal to the text "Sam" and gives TRUE if it is different
5IF Score <- 10 THEN EAnswer <- 5
6IF Age != 18 THEN FCambridge pseudocode uses <> for not equal, not !=. It should be IF Age <> 18 THEN

Definitions

= and <>

Fill in the Blanks

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

1.
IF Answer _ 5 THEN OUTPUT "Correct" ENDIF
2.
IF Name __ "Sam" THEN OUTPUT "Not Sam" ENDIF
3.
Answer __ 5
4.
IF Pet _ "cat" THEN OUTPUT "Meow" ENDIF
5.
WHILE Guess __ Answer DO INPUT Guess ENDWHILE

Spot the Error

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

Question 1
A DECLARE Answer : INTEGER
B Answer <- 5
C OUTPUT "Guess the number"
D IF Answer <- 5 THEN
E OUTPUT "Correct"
F ENDIF
Question 2
A DECLARE Name : STRING
B INPUT Name
C OUTPUT "Checking name"
D IF Name != "Sam" THEN
E OUTPUT "Not Sam"
F ENDIF
Question 3
A INPUT Answer
B IF Answer == 5 THEN
C OUTPUT "Correct"
D ENDIF
Question 4
A INPUT Name
B IF Name <> Sam THEN
C OUTPUT "Access denied"
D ENDIF
Question 5
A DECLARE Answer : INTEGER
B Answer <- 0
C WHILE Answer = 5 DO
D INPUT Answer
E ENDWHILE

Answer Key

Relational operators: = and <>
Section A: Quick Questions
Q1
B — IF Answer = 5 THEN
Q2
B — Answer <- 5
Q3
A — TRUE
Q4
A — FALSE
Q5
A — <>
Section B: Match the Pairs
Q1
Answer = 5 → Tests whether Answer is equal to 5 and gives TRUE or FALSE
Q2
Name <> "Sam" → Tests whether Name is not equal to the text "Sam" and gives TRUE if it is different
Q3
Use <- (not =) when you want to store a value in a variable → Answer <- 5
Q4
Use = inside an IF condition to check whether text matches exactly → IF Colour = "red" THEN
Q5
IF Score <- 10 THEN → <- is assignment, not a comparison. A condition should use = to test equality: IF Score = 10 THEN
Q6
IF Age != 18 THEN → Cambridge pseudocode uses <> for not equal, not !=. It should be IF Age <> 18 THEN
Section C: Definitions
Q1
= and <> — = tests whether two values are equal and <> tests whether they are not equal. Each gives TRUE or FALSE. Assignment uses <- instead, not =.
Section D: Fill in the Blanks
Q1
IF Answer = 5 THEN OUTPUT "Correct" ENDIF
Q2
IF Name <> "Sam" THEN OUTPUT "Not Sam" ENDIF
Q3
Answer <- 5
Q4
IF Pet = "cat" THEN OUTPUT "Meow" ENDIF
Q5
WHILE Guess <> Answer DO INPUT Guess ENDWHILE
Section E: Spot the Error
Q1
D — <- is assignment, not a test. A condition must use = to compare Answer with 5. It should be IF Answer = 5 THEN.
Q2
D — Cambridge pseudocode uses <> for 'not equal to', not !=. It should be IF Name <> "Sam" THEN.
Q3
B — Pseudocode uses a single = to test whether two values are equal. == belongs to other languages. It should be IF Answer = 5 THEN.
Q4
B — Text values must be in double quotes. Without them, Sam looks like a variable name. It should be IF Name <> "Sam" THEN.
Q5
C — The loop should keep asking while the answer is NOT 5. With = the condition is FALSE at the start, so the loop never runs. It should be WHILE Answer <> 5 DO.