IF ... THEN ... ENDIF (7c)

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

IF ... THEN ... ENDIF (7c)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is the correct way to write a simple IF statement in IGCSE pseudocode?
A IF Score > 50 THEN OUTPUT "Pass" ENDIF
B IF Score > 50 THEN OUTPUT "Pass"
2. Score is 40. The code is: IF Score > 50 THEN OUTPUT "Pass" ENDIF. What happens?
A Nothing is output, because the statements are skipped
B "Pass" is output
3. Score is 70. The code is: IF Score > 50 THEN OUTPUT "Pass" ENDIF. What happens?
A "Pass" is output
B Nothing is output
4. When do the statements between THEN and ENDIF run?
A Every time the program runs
B Only when the condition is TRUE
5. What does the keyword ENDIF do?
A Stops the whole program
B Marks the end of the IF statement

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 OUTPUT "Pass" ENDIF AOutputs Pass only when Score is greater than 50; otherwise nothing happens
2ENDIF BIF Age >= 16 THEN OUTPUT "Can apply" ENDIF
3The statements between THEN and ENDIF run only when the condition is TRUE CThe ENDIF is missing, so the IF statement is never closed and it is unclear where the IF ends
4Every IF statement must be closed with its own ENDIF DIF Temp < 0 THEN OUTPUT "Ice" ENDIF
5IF Score > 50 THEN OUTPUT "Pass" ETHEN is missing after the condition, so the IF line is incomplete
6IF Score > 50 OUTPUT "Pass" ENDIF FCloses an IF statement and marks where the statements that depend on the condition end

Definitions

IF ... 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" _____
4.
IF Score _ 50 THEN OUTPUT "Pass" ENDIF
5.
IF Score > 50 THEN ______ "Pass" 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 Score > 50
B OUTPUT "Pass"
C ENDIF
Question 3
A IF Mark >= 40 THEN
B OUTPUT "Pass"
C ENDWHILE
D OUTPUT "Done"
Question 4
A INPUT Temp
B OUTPUT "Checking"
C IF Temp ← 30 THEN
D OUTPUT "Hot"
E ENDIF
Question 5
A INPUT Score
B IF Score > 50 THEN
C OUTPUT "Fail"
D ENDIF

Answer Key

IF ... THEN ... ENDIF (7c)
Section A: Quick Questions
Q1
A — IF Score > 50 THEN OUTPUT "Pass" ENDIF
Q2
A — Nothing is output, because the statements are skipped
Q3
A — "Pass" is output
Q4
B — Only when the condition is TRUE
Q5
B — Marks the end of the IF statement
Section B: Match the Pairs
Q1
IF Score > 50 THEN OUTPUT "Pass" ENDIF → Outputs Pass only when Score is greater than 50; otherwise nothing happens
Q2
ENDIF → Closes an IF statement and marks where the statements that depend on the condition end
Q3
The statements between THEN and ENDIF run only when the condition is TRUE → IF Age >= 16 THEN OUTPUT "Can apply" ENDIF
Q4
Every IF statement must be closed with its own ENDIF → IF Temp < 0 THEN OUTPUT "Ice" ENDIF
Q5
IF Score > 50 THEN OUTPUT "Pass" → The ENDIF is missing, so the IF statement is never closed and it is unclear where the IF ends
Q6
IF Score > 50 OUTPUT "Pass" ENDIF → THEN is missing after the condition, so the IF line is incomplete
Section C: Definitions
Q1
IF ... THEN ... ENDIF — Runs the statements between THEN and ENDIF only when the condition is TRUE. If it is FALSE, they are skipped. Every IF must be closed with ENDIF, e.g. IF Score > 50 THEN OUTPUT "Pass" ENDIF.
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 "Pass" ENDIF
Section E: Spot the Error
Q1
C — Text to be displayed must be written as a string literal in double quotes. Without quotes, Pass looks like a variable. It should be OUTPUT "Pass".
Q2
A — The condition must be followed by THEN, which introduces the statements that run when the condition is TRUE. It should be IF Score > 50 THEN.
Q3
C — An IF statement must be closed with ENDIF. ENDWHILE closes a WHILE loop, not an IF. The line should be ENDIF.
Q4
C — A condition needs a relational operator to compare values. The arrow ← is assignment, not a comparison. It should be IF Temp > 30 THEN.
Q5
B — The wrong relational operator makes the condition TRUE for high scores, so "Fail" would be output for students who passed. It should be IF Score < 50 THEN.