IF…THEN…ENDIF (8.1b)

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

IF…THEN…ENDIF (8.1b)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Score is 62. What happens to OUTPUT "Pass" in: IF Score >= 50 THEN / OUTPUT "Pass" / ENDIF?
A It runs, because 62 >= 50 is TRUE
B It is skipped, because 62 >= 50 is FALSE
2. Score is 35. What happens to OUTPUT "Pass" in: IF Score >= 50 THEN / OUTPUT "Pass" / ENDIF?
A It is skipped and the program carries on after ENDIF
B The program stops with an error
3. Which is the correct way to close a selection in Cambridge pseudocode?
A END IF THEN
B ENDIF
4. Which layout is correct?
A IF Score >= 50 THEN (newline) indented OUTPUT "Pass" (newline) ENDIF lined up with IF
B IF Score >= 50 THEN (newline) indented OUTPUT "Pass" (newline) ENDIF indented like the OUTPUT
5. Which IF line is written correctly?
A IF Score >= 50
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 AStarts a selection that runs the indented lines below only when Score is 50 or more
2ENDIF BIF Score >= 50 THEN Passed <- Passed + 1 OUTPUT "Pass" ENDIF
3When the condition is FALSE, the statements in the THEN branch are skipped and the program carries on after ENDIF CIF Age >= 18 THEN OUTPUT "Adult" ENDIF OUTPUT "Done"
4The THEN branch can hold more than one indented statement, and all of them run only when the condition is TRUE DCloses the IF statement and lines up directly under the IF it belongs to
5IF Score >= 50 THEN OUTPUT "Pass" ETHEN is missing after the condition
6IF Score >= 50 OUTPUT "Pass" ENDIF FThe ENDIF is missing, so the IF statement is never closed

Definitions

IF condition THEN ... ENDIF

Fill in the Blanks

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

1.
__ Score >= 50 THEN OUTPUT "Pass" ENDIF
2.
IF Score >= 50 ____ OUTPUT "Pass" ENDIF
3.
IF Score __ 50 THEN OUTPUT "Pass" ENDIF
4.
IF Score >= 50 THEN OUTPUT "Pass" _____
5.
IF Score >= 50 THEN ______ "Well done" ENDIF

Spot the Error

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

Question 1
A INPUT Score
B IF Score >= 50 THEN
C OUTPUT "Pass
D ENDIF
Question 2
A IF Mark > 90 THEN
B OUTPUT "Top mark"
C ENDWHILE
Question 3
A INPUT Age
B IF Age >= 16
C OUTPUT "Can apply"
D ENDIF
Question 4
A IF Score >= 50 THEN
B OUTPUT "Pass"
C Passes = Passes + 1
D ENDIF
Question 5
A INPUT Temp
B IF Temp <- 30 THEN
C OUTPUT "Exactly 30"
D ENDIF

Answer Key

IF…THEN…ENDIF (8.1b)
Section A: Quick Questions
Q1
A — It runs, because 62 >= 50 is TRUE
Q2
A — It is skipped and the program carries on after ENDIF
Q3
B — ENDIF
Q4
A — IF Score >= 50 THEN (newline) indented OUTPUT "Pass" (newline) ENDIF lined up with IF
Q5
B — IF Score >= 50 THEN
Section B: Match the Pairs
Q1
IF Score >= 50 THEN → Starts a selection that runs the indented lines below only when Score is 50 or more
Q2
ENDIF → Closes the IF statement and lines up directly under the IF it belongs to
Q3
When the condition is FALSE, the statements in the THEN branch are skipped and the program carries on after ENDIF → IF Age >= 18 THEN OUTPUT "Adult" ENDIF OUTPUT "Done"
Q4
The THEN branch can hold more than one indented statement, and all of them run only when the condition is TRUE → IF Score >= 50 THEN Passed <- Passed + 1 OUTPUT "Pass" ENDIF
Q5
IF Score >= 50 THEN OUTPUT "Pass" → The ENDIF is missing, so the IF statement is never closed
Q6
IF Score >= 50 OUTPUT "Pass" ENDIF → THEN is missing after the condition
Section C: Definitions
Q1
IF condition THEN ... ENDIF — Runs the indented statements only when the condition is TRUE. If it is FALSE they are skipped. ENDIF closes the selection and lines up with IF.
Section D: Fill in the Blanks
Q1
IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Q2
IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Q3
IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Q4
IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Q5
IF Score >= 50 THEN OUTPUT "Well done" ENDIF
Section E: Spot the Error
Q1
C — The text to output is missing its closing quotation mark. It should be ' OUTPUT "Pass"'.
Q2
C — An IF selection is closed with ENDIF, not ENDWHILE. ENDWHILE closes a WHILE loop.
Q3
B — The IF line is missing the keyword THEN after the condition. It should be 'IF Age >= 16 THEN'.
Q4
C — Assignment uses the arrow <-. A single = is a comparison in Cambridge pseudocode. It should be 'Passes <- Passes + 1'.
Q5
B — A condition compares values, so it needs the relational operator =. The arrow <- is for assignment. It should be 'IF Temp = 30 THEN'.