Drawing a loop with a compound exit condition in a flowchart

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

Drawing a loop with a compound exit condition in a flowchart

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A WHILE loop test is: attempts < 3 AND password is wrong. How is it drawn?
A One diamond with the whole test, or two diamonds in a row, and an arrow back to the first question when the test is true
B One diamond with only attempts < 3, and the password check is left out of the flowchart
2. A loop stops when score >= 100 OR lives = 0. Which flowchart shows this correctly?
A Both reasons (score >= 100 and lives = 0) lead out of the loop
B Only score >= 100 leads out of the loop and lives = 0 goes back into the loop
3. What does the arrow going back in a loop flowchart point to?
A The Start symbol at the top of the flowchart
B The first question (diamond) of the loop test
4. A REPEAT loop stops when guess = secret OR guesses = 5. How many exit reasons must the flowchart show?
A One: the loop can only ever have one way out
B Two: one for guess = secret and one for guesses = 5
5. A loop uses two diamonds in a row to test: age >= 13 AND age <= 19. Where does a No from either diamond go?
A To the same place, because failing either part means the whole AND test is false
B Each No goes to a different place, so the two diamonds act separately

Match the Pairs

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

Left columnRight column
1WHILE lives > 0 AND time > 0 DO AD1: lives > 0? No -> exit. Yes -> D2: time > 0? No -> exit. Yes -> body -> arrow back to D1
2REPEAT ... UNTIL score >= 10 OR lives = 0 BDrawn as one combined diamond 'lives > 0 AND time > 0?'. Yes goes through the body and back to the diamond. No leaves the loop.
3A WHILE loop with AND can be drawn as two diamonds in a row. A No from either diamond leaves the loop, and the back arrow returns to the first diamond. CThe back arrow returns to the second diamond, so lives > 0 is never rechecked after the first pass. It must return to the first question.
4A REPEAT...UNTIL loop with OR can be drawn as two diamonds whose Yes paths both lead to the same exit. The No path of the last diamond goes back to the start. DA diamond after the loop body. Yes (either exit reason is true) leaves the loop. No takes the back arrow to the first step of the loop.
5D1: lives > 0? No -> exit. Yes -> D2: time > 0? No -> body. Yes -> body -> back to D1 EThe No path of the second diamond goes to the body instead of leaving the loop, so running out of time never stops the loop. Both exit reasons must lead out of the loop.
6D1: lives > 0? Yes -> D2: time > 0? Yes -> body -> arrow back to D2 Fbody -> score >= 10? Yes -> exit. No -> lives = 0? Yes -> exit. No -> arrow back to body

Definitions

compound loop exit

Fill in the Blanks

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

1.
Diamond: lives > 0 ___ time > 0? Yes -> run the loop body, then back up No -> exit the loop
2.
REPEAT tries ← tries + 1 UNTIL guess = secret __ tries = 3
3.
Diamond 1: guess = secret? Yes -> exit Diamond 2: tries = 3? Yes -> exit Diamond 2 No -> back to _________
4.
WHILE ___ (score >= 50 OR lives = 0) DO PLAY round ENDWHILE
5.
Process: attempts ← attempts + 1 Diamond: attempts __ 3 OR found = TRUE? Yes -> exit, No -> back to first question

Spot the Error

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

Question 1
A D: tries < 5 AND guess <> 7?
B Yes: input guess
C Arrow on to the END box
D No: leave loop
Question 2
A D1: lives > 0?
B D1 Yes: D2 time > 0?
C D2 Yes: play, arrow back to D2
D D1 No or D2 No: exit loop
Question 3
A Input guess
B D: guess = 7 AND tries = 3?
C Yes: leave the loop
D No: arrow back to Input guess
Question 4
A Start of loop: Input pin
B D: pin <> 1234 OR tries = 3?
C Yes: arrow to exit
D No: arrow back to Input pin
Question 5
A D1: fuel > 0?
B D1 No: exit loop
C D1 Yes: drive, back to D1
D D2 No: exit loop
E D2 Yes: drive, back to D1

Answer Key

Drawing a loop with a compound exit condition in a flowchart
Section A: Quick Questions
Q1
A — One diamond with the whole test, or two diamonds in a row, and an arrow back to the first question when the test is true
Q2
A — Both reasons (score >= 100 and lives = 0) lead out of the loop
Q3
B — The first question (diamond) of the loop test
Q4
B — Two: one for guess = secret and one for guesses = 5
Q5
A — To the same place, because failing either part means the whole AND test is false
Section B: Match the Pairs
Q1
WHILE lives > 0 AND time > 0 DO → Drawn as one combined diamond 'lives > 0 AND time > 0?'. Yes goes through the body and back to the diamond. No leaves the loop.
Q2
REPEAT ... UNTIL score >= 10 OR lives = 0 → A diamond after the loop body. Yes (either exit reason is true) leaves the loop. No takes the back arrow to the first step of the loop.
Q3
A WHILE loop with AND can be drawn as two diamonds in a row. A No from either diamond leaves the loop, and the back arrow returns to the first diamond. → D1: lives > 0? No -> exit. Yes -> D2: time > 0? No -> exit. Yes -> body -> arrow back to D1
Q4
A REPEAT...UNTIL loop with OR can be drawn as two diamonds whose Yes paths both lead to the same exit. The No path of the last diamond goes back to the start. → body -> score >= 10? Yes -> exit. No -> lives = 0? Yes -> exit. No -> arrow back to body
Q5
D1: lives > 0? No -> exit. Yes -> D2: time > 0? No -> body. Yes -> body -> back to D1 → The No path of the second diamond goes to the body instead of leaving the loop, so running out of time never stops the loop. Both exit reasons must lead out of the loop.
Q6
D1: lives > 0? Yes -> D2: time > 0? Yes -> body -> arrow back to D2 → The back arrow returns to the second diamond, so lives > 0 is never rechecked after the first pass. It must return to the first question.
Section C: Definitions
Q1
compound loop exit — A loop test using AND or OR is drawn as a back arrow to the first question, with one combined diamond or two diamonds. Both exit reasons must lead out of the loop.
Section D: Fill in the Blanks
Q1
Diamond: lives > 0 AND time > 0? Yes -> run the loop body, then back up No -> exit the loop
Q2
REPEAT tries ← tries + 1 UNTIL guess = secret OR tries = 3
Q3
Diamond 1: guess = secret? Yes -> exit Diamond 2: tries = 3? Yes -> exit Diamond 2 No -> back to Diamond 1
Q4
WHILE NOT (score >= 50 OR lives = 0) DO PLAY round ENDWHILE
Q5
Process: attempts ← attempts + 1 Diamond: attempts >= 3 OR found = TRUE? Yes -> exit, No -> back to first question
Section E: Spot the Error
Q1
C — After the Yes branch, the loop needs an arrow going back up to the diamond (the first question). Going on to END means the loop never repeats.
Q2
C — The back arrow must return to the first question, D1. Returning to D2 means lives are never checked again. It should say 'arrow back to D1'.
Q3
B — There are two separate reasons to exit: a correct guess or three tries. Either one should stop the loop, so the diamond needs OR. AND would only exit when both are true.
Q4
B — The first exit reason is a correct pin, so the test must be pin = 1234. Using <> would exit the loop when the pin is wrong.
Q5
C — With two diamonds, the Yes branch of D1 must lead to the second diamond D2. Skipping D2 means the distance is never tested, so that exit reason is lost.