Flowchart for a WHILE loop

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

Flowchart for a WHILE loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In a flowchart for a WHILE loop, where is the decision diamond drawn?
A Before the loop body
B After the loop body
2. A WHILE loop starts and its condition is false straight away. How many times does the body run?
A At least once
B Zero times
3. Which path from the decision runs the loop body in a WHILE flowchart?
A The Yes path
B The No path
4. After the last statement in the loop body, where does the flow line go?
A Straight on to the next step after the loop
B Back up to the decision
5. What happens on the No path from the decision in a WHILE flowchart?
A The loop ends and the flow moves to the next step
B The body runs one more time and then stops

Match the Pairs

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

Left columnRight column
1Decision diamond: Count <= 5 ? placed before the loop body AAfter the body runs, the flow returns to the condition so it can be tested again.
2Arrow from the end of the loop body back up to the decision diamond BThere is no arrow from the end of the body back to the decision, so the loop cannot repeat and the body only ever runs once.
3The Yes path from the decision runs the loop body, then returns to the decision CCount <= 5 ? --No--> OUTPUT "Finished"
4The No path leaves the loop and continues to the next step of the algorithm DCount <= 5 ? --Yes--> OUTPUT Count --> Count <- Count + 1 --> back to Count <= 5 ?
5Start --> Count <- 1 --> OUTPUT Count --> Count <- Count + 1 --> Count <= 5 ? --Yes--> back to OUTPUT Count EThis is the test of a WHILE loop. It is checked first, so the body may run zero times if the condition is false at the start.
6Count <= 5 ? --Yes--> OUTPUT Count --> Count <- Count + 1 --> OUTPUT "Done" FThe body is placed before the decision, which draws a REPEAT ... UNTIL style loop. The body must run at least once, but a WHILE body may run zero times.

Definitions

WHILE condition DO

Fill in the Blanks

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

1.
_____ Count <= 5 DO OUTPUT Count ENDWHILE
2.
WHILE Count __ 5 DO Count ← Count + 1 ENDWHILE
3.
Decision: Count <= 5? Yes: body, then arrow back to the ________ No: go to next step
4.
Decision: Total < 20? __: leave the loop Yes: run the body
5.
Count ← 6 WHILE Count <= 5 DO // body runs _ times

Spot the Error

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

Question 1
A START
B Count ← 1
C Decision: Count <= 3?
D Yes: body, arrow to STOP
E No: go to next step
Question 2
A Body first, then Num > 0?
B Yes: Total ← Total + Num
C Yes: arrow back to decision
D No: exit to OUTPUT Total
Question 3
A Lives ← 3
B Process: Lives > 0?
C Yes: Lives ← Lives - 1, back
D No: next step
Question 4
A START
B OUTPUT Num
C Decision: Num < 10?
D Yes: INPUT Num, arrow back
E No: OUTPUT Num
Question 5
A START
B Total ← 0
C Decision: Total > 50?
D Yes: add Mark, arrow back
E No: OUTPUT Total

Answer Key

Flowchart for a WHILE loop
Section A: Quick Questions
Q1
A — Before the loop body
Q2
B — Zero times
Q3
A — The Yes path
Q4
B — Back up to the decision
Q5
A — The loop ends and the flow moves to the next step
Section B: Match the Pairs
Q1
Decision diamond: Count <= 5 ? placed before the loop body → This is the test of a WHILE loop. It is checked first, so the body may run zero times if the condition is false at the start.
Q2
Arrow from the end of the loop body back up to the decision diamond → After the body runs, the flow returns to the condition so it can be tested again.
Q3
The Yes path from the decision runs the loop body, then returns to the decision → Count <= 5 ? --Yes--> OUTPUT Count --> Count <- Count + 1 --> back to Count <= 5 ?
Q4
The No path leaves the loop and continues to the next step of the algorithm → Count <= 5 ? --No--> OUTPUT "Finished"
Q5
Start --> Count <- 1 --> OUTPUT Count --> Count <- Count + 1 --> Count <= 5 ? --Yes--> back to OUTPUT Count → The body is placed before the decision, which draws a REPEAT ... UNTIL style loop. The body must run at least once, but a WHILE body may run zero times.
Q6
Count <= 5 ? --Yes--> OUTPUT Count --> Count <- Count + 1 --> OUTPUT "Done" → There is no arrow from the end of the body back to the decision, so the loop cannot repeat and the body only ever runs once.
Section C: Definitions
Q1
WHILE condition DO — In a flowchart the decision comes first. Yes runs the body and an arrow returns to the decision. No leaves the loop to the next step. The body may run zero times.
Section D: Fill in the Blanks
Q1
WHILE Count <= 5 DO OUTPUT Count ENDWHILE
Q2
WHILE Count <= 5 DO Count ← Count + 1 ENDWHILE
Q3
Decision: Count <= 5? Yes: body, then arrow back to the decision No: go to next step
Q4
Decision: Total < 20? No: leave the loop Yes: run the body
Q5
Count ← 6 WHILE Count <= 5 DO // body runs 0 times
Section E: Spot the Error
Q1
D — In a WHILE loop the Yes path runs the body and then an arrow goes back to the decision. It must not leave the loop. The line should be 'Yes: body, arrow to decision'.
Q2
A — A WHILE loop is drawn with the decision before the body. The body-first version is a REPEAT loop. It should be 'Decision: Num > 0?'.
Q3
B — A condition with Yes and No paths is a decision, drawn as a diamond. It is not a process rectangle. It should be 'Decision: Lives > 0?'.
Q4
B — The first value must be read in before the decision is tested, so the loop has a value to check. Outputting Num here uses it before it has a value. It should be 'INPUT Num'.
Q5
C — Total starts at 0, so Total > 50 is false straight away. The body would be skipped and the loop would never total anything. The condition should be Total < 50.