Menu

Flowcharts

Nesting in Flowcharts

Nesting means putting one construct inside another — a decision inside a loop, or a loop inside a decision. Nothing extra is added to show nesting: it is shown by the arrangement of the symbols and the direction of the arrows.

How nesting is shown

A nested construct sits physically inside the shape of the other one. If a decision diamond sits inside the body of a loop — between where the loop starts and the arrow that leads back — that decision is inside the loop. If a loop's arrow starts and returns inside one exit of a decision, the loop exists only on that branch. You read nesting by tracing where the arrows go, so a flowchart needs no special symbol for it.

A decision inside a loop

Example: a snack machine keeps asking for an item code until the shopper presses cancel. Inside that loop, a diamond checks whether the code matches a stocked item and prints either "Dispensing" or "Unknown code". Because the diamond sits in the loop, it is reached and tested again on every pass, so it can give a different result each time as different codes are typed.

A loop inside a decision

Example: a car wash asks whether the driver wants the deluxe package. Only the "yes" exit contains a loop that keeps asking for extra wax coats until the driver answers no; the "no" exit goes straight to the wash. The loop runs on that branch alone — a driver who answers no never reaches it, and the decision itself is asked only once.

Nesting is what lets one flowchart show selection and iteration together, so a single diagram can describe a realistic algorithm rather than stopping after one construct.

Practise this