Error: missing ENDIF, NEXT, ENDWHILE or UNTIL

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

Error: missing ENDIF, NEXT, ENDWHILE or UNTIL

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which IF statement is closed correctly? A: IF Score > 50 THEN OUTPUT "Pass" ENDIF B: IF Score > 50 THEN OUTPUT "Pass" ENDWHILE
A A: it ends with ENDIF
B B: it ends with ENDWHILE
2. A FOR loop starts with FOR Count ← 1 TO 5. Which closing line is correct?
A NEXT Counter
B NEXT Count
3. A student writes a REPEAT loop and ends it with ENDWHILE. Is this correct?
A No. A REPEAT loop must end with UNTIL and a condition
B Yes. ENDWHILE can close any loop
4. Which statement about a nested IF is true? IF A > 0 THEN IF B > 0 THEN OUTPUT "Both"
A It needs two ENDIFs, one for each IF
B One ENDIF at the end closes both IF statements
5. Which WHILE loop is closed correctly? A: WHILE Lives > 0 DO Lives ← Lives - 1 ENDWHILE B: WHILE Lives > 0 DO Lives ← Lives - 1 UNTIL Lives = 0
A B: it ends with UNTIL
B A: it ends with ENDWHILE

Match the Pairs

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

Left columnRight column
1NEXT Counter ACloses a FOR loop whose counter variable is Counter
2ENDWHILE BNEXT uses a different identifier (Total) from the FOR loop counter (Count). It should be NEXT Count.
3A REPEAT loop must end with UNTIL and a condition, not with ENDWHILE CCloses a WHILE ... DO loop
4A nested IF needs its own ENDIF, so two IF statements need two ENDIF keywords DIF Mark >= 50 THEN IF Mark >= 80 THEN OUTPUT "Distinction" ENDIF ENDIF
5FOR Count ← 1 TO 10 OUTPUT Count NEXT Total EENDWHILE has been used to close a REPEAT loop. It should be UNTIL with a condition, such as UNTIL Answer = 5.
6REPEAT INPUT Answer ENDWHILE FREPEAT INPUT Number UNTIL Number > 0

Definitions

ENDIF NEXT ENDWHILE UNTIL

Fill in the Blanks

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

1.
FOR Count ← 1 TO 5 OUTPUT Count NEXT _____
2.
IF Score > 50 THEN OUTPUT "Pass" _____
3.
WHILE Total < 100 DO Total ← Total + 5 ________
4.
REPEAT INPUT Guess _____ Guess = 7
5.
IF Age > 0 THEN IF Age > 9 THEN OUTPUT "Big" ENDIF _____

Spot the Error

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

Question 1
A FOR Num ← 1 TO 5
B OUTPUT Count
C NEXT Count
Question 2
A Count ← 0
B WHILE Count < 3 DO
C Count ← Count + 1
D ENDIF
Question 3
A REPEAT
B INPUT Pin
C ENDWHILE
Question 4
A IF Mark >= 50 THEN
B WHILE Mark >= 80 DO
C OUTPUT "High"
D ENDIF
E ENDIF
Question 5
A FOR Row ← 1 TO 3
B FOR Num ← 1 TO 4
C OUTPUT Row * Col
D NEXT Col
E NEXT Row

Answer Key

Error: missing ENDIF, NEXT, ENDWHILE or UNTIL
Section A: Quick Questions
Q1
A — A: it ends with ENDIF
Q2
B — NEXT Count
Q3
A — No. A REPEAT loop must end with UNTIL and a condition
Q4
A — It needs two ENDIFs, one for each IF
Q5
B — A: it ends with ENDWHILE
Section B: Match the Pairs
Q1
NEXT Counter → Closes a FOR loop whose counter variable is Counter
Q2
ENDWHILE → Closes a WHILE ... DO loop
Q3
A REPEAT loop must end with UNTIL and a condition, not with ENDWHILE → REPEAT INPUT Number UNTIL Number > 0
Q4
A nested IF needs its own ENDIF, so two IF statements need two ENDIF keywords → IF Mark >= 50 THEN IF Mark >= 80 THEN OUTPUT "Distinction" ENDIF ENDIF
Q5
FOR Count ← 1 TO 10 OUTPUT Count NEXT Total → NEXT uses a different identifier (Total) from the FOR loop counter (Count). It should be NEXT Count.
Q6
REPEAT INPUT Answer ENDWHILE → ENDWHILE has been used to close a REPEAT loop. It should be UNTIL with a condition, such as UNTIL Answer = 5.
Section C: Definitions
Q1
ENDIF NEXT ENDWHILE UNTIL — Closing keywords that end IF, FOR, WHILE and REPEAT. Each one must match its opening statement. A missing or mismatched closing keyword is an error.
Section D: Fill in the Blanks
Q1
FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Q2
IF Score > 50 THEN OUTPUT "Pass" ENDIF
Q3
WHILE Total < 100 DO Total ← Total + 5 ENDWHILE
Q4
REPEAT INPUT Guess UNTIL Guess = 7
Q5
IF Age > 0 THEN IF Age > 9 THEN OUTPUT "Big" ENDIF ENDIF
Section E: Spot the Error
Q1
A — The loop counter is now Num, but the loop is closed with NEXT Count. NEXT must use the same identifier as the FOR line. The first line should be FOR Count ← 1 TO 5.
Q2
D — A WHILE loop must be closed with ENDWHILE. ENDIF closes an IF statement, so it is the wrong closing keyword here.
Q3
C — A REPEAT loop is closed by UNTIL followed by a condition. ENDWHILE belongs to a WHILE loop. The line should be UNTIL Pin = 1234.
Q4
B — This line opens a WHILE loop, but the block is closed with ENDIF. The opening statement and closing keyword do not match. The line should be IF Mark >= 80 THEN.
Q5
B — The inner loop uses Num, but it is closed by NEXT Col. The identifier after NEXT must match the FOR line. The line should be FOR Col ← 1 TO 4.