Indenting THEN and ELSE by two spaces

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

Indenting THEN and ELSE by two spaces

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which layout puts THEN in the correct place?
A IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
B IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
2. How far is THEN indented from the IF line?
A Two spaces
B Four spaces
3. Where should ENDIF be written?
A Lined up with THEN and ELSE
B Lined up with the IF it closes
4. Which layout positions ELSE correctly?
A IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF
B IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF
5. Where do the statements inside THEN go?
A In line with THEN
B Further in than THEN

Match the Pairs

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

Left columnRight column
1IF Age >= 16 THEN OUTPUT "Adult" AENDIF is indented two spaces. It must line up with IF, in the same column.
2 ELSE OUTPUT "Child" BTHEN is on its own line, two spaces in from IF. The statement inside THEN is indented further.
3THEN and ELSE are two spaces in from IF, the statements inside are indented further, and ENDIF lines up with IF. CTHEN is not indented. It must be two spaces in from IF, with the OUTPUT statement indented further.
4A nested IF keeps the same two-space step. The inner IF sits inside THEN and its own ENDIF lines up with the inner IF. DELSE is on its own line, two spaces in from IF. The statement inside ELSE is indented further.
5IF Score >= 50 THEN OUTPUT "Pass" ENDIF EIF Age >= 16 THEN IF Age >= 65 THEN OUTPUT "Senior" ENDIF ENDIF
6IF Score >= 50 THEN OUTPUT "Pass" ENDIF FIF Score >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF

Definitions

THEN

Fill in the Blanks

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

1.
IF Score >= 50 ____ OUTPUT "Pass"
2.
THEN OUTPUT "Pass" ____
3.
ELSE OUTPUT "Fail" _____
4.
__ Mark >= 50 THEN OUTPUT "Pass"
5.
OUTPUT "Merit" ____ OUTPUT "Pass"

Spot the Error

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

Question 1
A IF Age >= 18
B THEN
C THEN OUTPUT "Adult"
D ELSE
E OUTPUT "Child"
F ENDIF
Question 2
A IF Score >= 50 THEN
B THEN
C OUTPUT "Pass"
D ELSE
E OUTPUT "Fail"
F ENDIF
Question 3
A INPUT Temp
B IF Temp > 30
C THEN OUTPUT "Hot"
D OUTPUT "Hot"
E ENDIF
Question 4
A IF Passed = TRUE
B THEN
C OUTPUT "Well done" ENDIF
D ENDIF
Question 5
A IF Coins >= 10
B THEN OUTPUT "Buy"
C OUTPUT "Buy"
D ENDIF

Answer Key

Indenting THEN and ELSE by two spaces
Section A: Quick Questions
Q1
A — IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Q2
A — Two spaces
Q3
B — Lined up with the IF it closes
Q4
A — IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF
Q5
B — Further in than THEN
Section B: Match the Pairs
Q1
IF Age >= 16 THEN OUTPUT "Adult" → THEN is on its own line, two spaces in from IF. The statement inside THEN is indented further.
Q2
ELSE OUTPUT "Child" → ELSE is on its own line, two spaces in from IF. The statement inside ELSE is indented further.
Q3
THEN and ELSE are two spaces in from IF, the statements inside are indented further, and ENDIF lines up with IF. → IF Score >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
Q4
A nested IF keeps the same two-space step. The inner IF sits inside THEN and its own ENDIF lines up with the inner IF. → IF Age >= 16 THEN IF Age >= 65 THEN OUTPUT "Senior" ENDIF ENDIF
Q5
IF Score >= 50 THEN OUTPUT "Pass" ENDIF → THEN is not indented. It must be two spaces in from IF, with the OUTPUT statement indented further.
Q6
IF Score >= 50 THEN OUTPUT "Pass" ENDIF → ENDIF is indented two spaces. It must line up with IF, in the same column.
Section C: Definitions
Q1
THEN — THEN and ELSE sit two spaces in from IF, on their own lines. The statements inside each go further in, and ENDIF lines up with IF. Nested IFs keep the same two-space step.
Section D: Fill in the Blanks
Q1
IF Score >= 50 THEN OUTPUT "Pass"
Q2
THEN OUTPUT "Pass" ELSE
Q3
ELSE OUTPUT "Fail" ENDIF
Q4
IF Mark >= 50 THEN OUTPUT "Pass"
Q5
OUTPUT "Merit" ELSE OUTPUT "Pass"
Section E: Spot the Error
Q1
C — THEN is already on line 2, on its own line two spaces in. The statement inside it must go on its own line, indented further to four spaces: ' OUTPUT "Adult"'.
Q2
A — THEN must not be written on the IF line. It goes on its own line, indented two spaces in from IF. Line 1 should be just 'IF Score >= 50'.
Q3
C — THEN sits on its own line, two spaces in from IF. The statement inside THEN belongs on the next line, indented four spaces: ' OUTPUT "Hot"'. The line should be just ' THEN'.
Q4
C — ENDIF must be on its own line, lined up with IF at the left margin. It must not be added to the end of the statement line. The line should be ' OUTPUT "Well done"'.
Q5
B — THEN stays on its own line, two spaces in from IF. The statement inside it goes on the next line, indented further. Line 2 should be just ' THEN'.