24 min read
Loops in Flowcharts
Repeat steps with a decision and an arrow that goes back up — counter-controlled and condition-controlled loops.
Iteration: Repeating Steps
A loop repeats steps. In a flowchart, a loop is a decision (diamond) plus an arrow that goes back up to an earlier step. There is no separate loop symbol: if a question asks which shape shows a loop, the answer is the diamond. The decision decides whether to go round again or to leave the loop.
Every loop needs three things:
- Start value — set before the loop (for example number = 1).
- Condition — checked in the decision (number <= 9?).
- Change — something inside the loop that moves towards the end (number = number + 2). Without it, the loop never ends.
A Counter-Controlled Loop: Odd Numbers 1 to 9
Output the odd numbers from 1 to 9
Read this flowchart as text
- Terminator: Start (then → number = 1)
- Process: number = 1 (then → number <= 9?)
- Decision: number <= 9? (Yes → OUTPUT number; No → Stop)
- Input/output: OUTPUT number (then → number = number + 2)
- Terminator: Stop
- Process: number = number + 2 (then → number <= 9?)
| Tracing the loop | ||
|---|---|---|
A Condition-Controlled Loop: Keep Adding Prices
Sometimes you do not know how many times to repeat. At the shop, the cashier enters prices one by one and types 0 when the customer has no more items. The 0 is a sentinel (rogue) value that ends the loop.
Add up prices until 0 is entered
Read this flowchart as text
- Terminator: Start (then → total = 0)
- Process: total = 0 (then → INPUT price)
- Input/output: INPUT price (then → price > 0?)
- Decision: price > 0? (Yes → total = total + price; No → OUTPUT total)
- Process: total = total + price (then → INPUT price)
- Input/output: OUTPUT total (then → Stop)
- Input/output: INPUT price (then → price > 0?)
- Terminator: Stop
Types of Loop
| Loop types | ||
|---|---|---|
Check your answer: multiples of 5 up to 30
Read this flowchart as text
- Terminator: Start (then → n = 5)
- Process: n = 5 (then → n <= 30?)
- Decision: n <= 30? (Yes → OUTPUT n; No → Stop)
- Input/output: OUTPUT n (then → n = n + 5)
- Terminator: Stop
- Process: n = n + 5 (then → n <= 30?)
Practice
More lessons in Algorithms, Flowcharts and Pseudocode · Next: Reading and Completing Flowcharts · Previous: Nested Decisions
