Boolean Operators in Pseudocode

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

Boolean Operators in Pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which boolean operator requires BOTH conditions to be true?
A OR — at least one must be true
B AND — both must be true
2. What does NOT found evaluate to when found is true?
A true — NOT confirms the value
B false — NOT reverses the value
3. Which is the correct way to write a compound AND condition in VCAA pseudocode?
A if x > 0 AND x < 10 then
B if x > 0 && x < 10 then
4. Which boolean operator makes a condition true when at least ONE of the sub-conditions is true?
A OR
B AND
5. Which is the correct VCAA pseudocode way to write a compound OR condition?
A if a < 0 OR a > 100 then
B if a < 0 || a > 100 then

Match the Pairs

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

Left columnRight column
1if x > 0 AND x < 100 then print "In range" end if Aif NOT found then print "Not found" end if
2if isStudent OR isSenior then print "Discount" end if BWrong — || is not valid VCAA pseudocode. The correct boolean operator is the word OR written in uppercase: `if a < 0 OR a > 100 then`
3AND is true only when BOTH of its conditions are true; if either is false the whole AND expression is false Cif age >= 18 AND hasID then print "Entry allowed" end if
4NOT reverses the truth value of the condition that follows it: NOT true becomes false, and NOT false becomes true DUses AND to combine two conditions — the then branch executes only when x is greater than 0 AND less than 100 at the same time
5if x > 0 && x < 10 then EWrong — && is not valid VCAA pseudocode. The correct boolean operator is the word AND written in uppercase: `if x > 0 AND x < 10 then`
6if a < 0 || a > 100 then FUses OR to combine two conditions — the then branch executes when either isStudent is true OR isSenior is true, or both

Definitions

AND

Fill in the Blanks

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

1.
if x > 0 ___ x < 10 then
2.
if a < 0 __ a > 100 then
3.
if ___ found then print "Not found" end if
4.
if age >= 18 ___ hasID then
5.
if isStudent __ isSenior then

Spot the Error

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

Question 1
A Algorithm: range check
B input n
C if n > 0 && n < 100 then
D print "In range"
E end if
Question 2
A Algorithm: check access
B input age, hasCard
C if age >= 18 OR hasCard then
D print "Access granted"
E else
F print "Denied"
Question 3
A Algorithm: not logged in
B input status
C if NOT status = true then
D print "Please log in"
E end if
Question 4
A Algorithm: validate input
B input x
C if x > 0 AND x < 50 then
D print "Valid"
E end if
Question 5
A Algorithm: even or small
B input n
C if n MOD 2 = 0 || n < 10 then
D print "Match"
E end if

Answer Key

Boolean Operators in Pseudocode
Section A: Quick Questions
Q1
B — AND — both must be true
Q2
B — false — NOT reverses the value
Q3
A — if x > 0 AND x < 10 then
Q4
A — OR
Q5
A — if a < 0 OR a > 100 then
Section B: Match the Pairs
Q1
if x > 0 AND x < 100 then print "In range" end if → Uses AND to combine two conditions — the then branch executes only when x is greater than 0 AND less than 100 at the same time
Q2
if isStudent OR isSenior then print "Discount" end if → Uses OR to combine two conditions — the then branch executes when either isStudent is true OR isSenior is true, or both
Q3
AND is true only when BOTH of its conditions are true; if either is false the whole AND expression is false → if age >= 18 AND hasID then print "Entry allowed" end if
Q4
NOT reverses the truth value of the condition that follows it: NOT true becomes false, and NOT false becomes true → if NOT found then print "Not found" end if
Q5
if x > 0 && x < 10 then → Wrong — && is not valid VCAA pseudocode. The correct boolean operator is the word AND written in uppercase: `if x > 0 AND x < 10 then`
Q6
if a < 0 || a > 100 then → Wrong — || is not valid VCAA pseudocode. The correct boolean operator is the word OR written in uppercase: `if a < 0 OR a > 100 then`
Section C: Definitions
Q1
AND — A VCAA pseudocode boolean operator that combines two conditions. The overall result is true only when BOTH conditions are true. Example: x > 0 AND x < 10
Section D: Fill in the Blanks
Q1
if x > 0 AND x < 10 then
Q2
if a < 0 OR a > 100 then
Q3
if NOT found then print "Not found" end if
Q4
if age >= 18 AND hasID then
Q5
if isStudent OR isSenior then
Section E: Spot the Error
Q1
C — `&&` is not a valid VCAA pseudocode operator. The correct boolean operator for combining two conditions that must both be true is the word `AND`. The line should read `if n > 0 AND n < 100 then`. Line 2 is wrong.
Q2
F — ` print "Denied"` is inside the else branch and is correctly indented. However the block is missing `end if` after line 5. The last line should be followed by `end if` but it is absent. Redesigning: line 5 reads `print "Denied"` without indentation, violating the convention that else-branch bodies must be indented. Line 5 is wrong.
Q3
A — The algorithm header is missing its colon. The correct form is `Algorithm: not logged in` with a colon after the keyword Algorithm. Line 0 is wrong.
Q4
D — ` print "Valid"` is the body of the if block and is correctly indented. However `"Valid"` should match the context. Looking for a genuine error: line 3 reads ` print "Valid"` which is fine. Redesigning: line 3 should read `print "Valid"` without indentation, violating the VCAA convention that if-block bodies must be indented. Line 3 is wrong.
Q5
C — `||` is not a valid VCAA pseudocode operator. The correct boolean operator for conditions where at least one must be true is the word `OR`. The line should read `if n MOD 2 = 0 OR n < 10 then`. Line 2 is wrong.