if-then block

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

if-then block

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which keyword is required to open the body of an if block in VCAA pseudocode?
A do — written after the condition
B then — written after the condition
2. How must the body of an if-then block be formatted in VCAA pseudocode?
A Indented to show it belongs inside the block
B Left-aligned with no indentation
3. Which correctly closes an if block in VCAA pseudocode?
A endif
B end if
4. What happens when the condition in an if-then block is false?
A The block body is skipped entirely
B The block body still executes
5. Which is the correct VCAA pseudocode structure for a single-branch if block?
A if score >= 50 then print "Pass" end if
B if score >= 50: print "Pass"

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 AAn if-then block with two body statements — both are indented inside the block and both execute only when n is not equal to zero
2if n != 0 then result <- 100 / n print result end if BA complete if-then block: condition opens with then, the body is indented, and end if closes the block; the body runs only when score >= 50 is true
3The body of an if-then block is skipped entirely when the condition is false — execution jumps to the line after end if CWrong — the body `print n` is not indented. The body of an if-then block must be indented to show it belongs inside the block
4end if closes the if block at the same indentation level as the opening if keyword Dif total > 0 then print total end if print "Done"
5if age >= 18 print "Adult" end if EWrong — the condition is missing the required `then` keyword. The correct form is `if age >= 18 then` with then after the condition
6if n > 0 then print n end if Fif x > 0 then x <- x + 1 end if

Definitions

end if

Fill in the Blanks

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

1.
if score >= 50 ____ print "Pass" end if
2.
if n > 0 then print n ___ if
3.
__ age >= 18 then print "Adult" end if
4.
if total > 100 then discount <- total / __ end if
5.
if x != 0 then result <- 100 / x ___ if

Spot the Error

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

Question 1
A Algorithm: flag positive
B input n
C if n > 0 then
D print "Positive"
E end if
Question 2
A Algorithm: check speed
B input speed
C if speed > 110
D print "Too fast"
E end if
Question 3
A Algorithm: check age
B input age
C if age >= 18 then
D print "Adult"
E endif
Question 4
A algorithm: check balance
B input balance
C if balance < 0 then
D print "Overdrawn"
E end if
Question 5
A Algorithm: check temp
B input temp
C if temp then > 30
D print "Hot"
E end if

Answer Key

if-then block
Section A: Quick Questions
Q1
B — then — written after the condition
Q2
A — Indented to show it belongs inside the block
Q3
B — end if
Q4
A — The block body is skipped entirely
Q5
A — if score >= 50 then print "Pass" end if
Section B: Match the Pairs
Q1
if score >= 50 then print "Pass" end if → A complete if-then block: condition opens with then, the body is indented, and end if closes the block; the body runs only when score >= 50 is true
Q2
if n != 0 then result <- 100 / n print result end if → An if-then block with two body statements — both are indented inside the block and both execute only when n is not equal to zero
Q3
The body of an if-then block is skipped entirely when the condition is false — execution jumps to the line after end if → if total > 0 then print total end if print "Done"
Q4
end if closes the if block at the same indentation level as the opening if keyword → if x > 0 then x <- x + 1 end if
Q5
if age >= 18 print "Adult" end if → Wrong — the condition is missing the required `then` keyword. The correct form is `if age >= 18 then` with then after the condition
Q6
if n > 0 then print n end if → Wrong — the body `print n` is not indented. The body of an if-then block must be indented to show it belongs inside the block
Section C: Definitions
Q1
end if — The closing keyword that ends an if-then block in VCAA pseudocode. Every if block must be closed with end if at the same indentation level as the opening if keyword
Section D: Fill in the Blanks
Q1
if score >= 50 then print "Pass" end if
Q2
if n > 0 then print n end if
Q3
if age >= 18 then print "Adult" end if
Q4
if total > 100 then discount <- total / 10 end if
Q5
if x != 0 then result <- 100 / x end if
Section E: Spot the Error
Q1
D — `print "Positive"` is inside the if block but is not indented. The body of an if-then block must be indented to show it belongs inside the block. The line should read ` print "Positive"` with leading spaces. Line 3 is wrong.
Q2
C — The if condition on line 2 is missing the `then` keyword. In VCAA pseudocode an if block must use the form `if condition then` — the word `then` is required to open the block body. Line 2 is wrong.
Q3
E — `endif` is written as one word, which is incorrect in VCAA pseudocode. The closing keyword must be written as two separate words: `end if` with a space between them. Line 4 is wrong.
Q4
A — The keyword `algorithm` uses a lowercase a. VCAA pseudocode requires the keyword to have a capital A: `Algorithm: check balance`. Line 0 is wrong.
Q5
C — `if temp then > 30` places `then` in the wrong position. The correct structure is `if condition then` — the condition comes before `then`. The line should read `if temp > 30 then`. Line 2 is wrong.