Flowchart for a FOR loop

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

Flowchart for a FOR loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Where is the counter first set in a FOR loop flowchart?
A In a process box before the decision
B Inside the decision diamond
2. Which shape holds the test Counter <= 10?
A Decision diamond
B Process rectangle
3. Which is the correct order for a FOR loop flowchart?
A Set counter, body, test, add 1, back to body
B Set counter, test, body, add 1, back to test
4. Which flowchart statement increases the counter?
A Counter = Counter + 1
B Counter ← Counter + 1
5. Where does the flow line from Counter ← Counter + 1 go?
A Back to the decision
B Back to Counter ← 1

Match the Pairs

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

Left columnRight column
1Counter ← 1 AProcess box before the test: sets the loop counter to its starting value once, before the loop begins
2Counter <= 10 BThe counter is reset to 1 on every pass, so it never reaches 10 and the loop never ends. The start value must be set once before the test.
3After the loop body, the counter is increased by 1 in a process box, then a flow line returns to the test CCounter ← Counter + 1
4The test comes before the body, so a FOR loop flowchart sets the counter first and checks it before running any body statements DDecision diamond: tests whether the loop should run again, Yes goes to the body and No leaves the loop
5Counter ← 1 placed inside the loop, after the body and just before the flow line back to the test ECounter ← 1 then Counter <= 10 ?
6Body, then flow line straight back to the test with no Counter ← Counter + 1 box FThe counter is never increased, so Counter <= 10 stays true forever and the loop runs endlessly. A process box adding 1 is missing.

Definitions

FOR loop flowchart

Fill in the Blanks

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

1.
Process box: Counter ← _
2.
Decision box: Counter __ 10
3.
After body: Counter ← Counter _ 1
4.
Decision: Counter <= 10? ___ runs the body
5.
Decision: Counter <= 10? __ leaves the loop

Spot the Error

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

Question 1
A Process: Counter ← 1
B Decision: Counter <= 10
C No: OUTPUT Counter
D Process: Counter ← Counter + 1
E Flow: back to the decision
Question 2
A Process: Counter ← 1
B Decision: Counter >= 5
C Yes: OUTPUT Counter
D Process: Counter ← Counter + 1
E Flow: back to the decision
Question 3
A Process: Counter ← 1
B Decision: Counter < 20
C Yes: OUTPUT Counter
D Process: Counter ← Counter + 1
E Flow: back to the decision
Question 4
A Process: Counter = 1
B Decision: Counter <= 10
C Yes: OUTPUT Counter
D Process: Counter ← Counter + 1
E Flow: back to the decision
Question 5
A Process: Counter ← 1
B Process: Counter <= 10
C Yes: OUTPUT Counter * 2
D Process: Counter ← Counter + 1
E Flow: back to the decision

Answer Key

Flowchart for a FOR loop
Section A: Quick Questions
Q1
A — In a process box before the decision
Q2
A — Decision diamond
Q3
B — Set counter, test, body, add 1, back to test
Q4
B — Counter ← Counter + 1
Q5
A — Back to the decision
Section B: Match the Pairs
Q1
Counter ← 1 → Process box before the test: sets the loop counter to its starting value once, before the loop begins
Q2
Counter <= 10 → Decision diamond: tests whether the loop should run again, Yes goes to the body and No leaves the loop
Q3
After the loop body, the counter is increased by 1 in a process box, then a flow line returns to the test → Counter ← Counter + 1
Q4
The test comes before the body, so a FOR loop flowchart sets the counter first and checks it before running any body statements → Counter ← 1 then Counter <= 10 ?
Q5
Counter ← 1 placed inside the loop, after the body and just before the flow line back to the test → The counter is reset to 1 on every pass, so it never reaches 10 and the loop never ends. The start value must be set once before the test.
Q6
Body, then flow line straight back to the test with no Counter ← Counter + 1 box → The counter is never increased, so Counter <= 10 stays true forever and the loop runs endlessly. A process box adding 1 is missing.
Section C: Definitions
Q1
FOR loop flowchart — Set Counter ← 1 in a process box, test Counter <= 10 in a decision, run the body on Yes, then do Counter ← Counter + 1 and flow back to the test. No leaves the loop.
Section D: Fill in the Blanks
Q1
Process box: Counter ← 1
Q2
Decision box: Counter <= 10
Q3
After body: Counter ← Counter + 1
Q4
Decision: Counter <= 10? Yes runs the body
Q5
Decision: Counter <= 10? No leaves the loop
Section E: Spot the Error
Q1
C — The loop body runs on the Yes branch, when the test Counter <= 10 is true. The No branch leaves the loop. The line should be Yes: OUTPUT Counter.
Q2
B — Counter starts at 1, so Counter >= 5 is false straight away and the body never runs. The decision must be Counter <= 5.
Q3
B — Counter < 20 stops the loop before 20 is output, so it runs only 19 times. To include 20 the decision must be Counter <= 20.
Q4
A — Setting the counter is an assignment, so it needs the assignment arrow. The = sign is used for comparing. It should be Counter ← 1.
Q5
B — A test must be drawn in a decision (diamond) with Yes and No exits, not in a process box. It should be Decision: Counter <= 10.