Home/Blog/Guide & Examples

Structogram Loops Explained: While, Do-While & For Loops

2026-11-227 min read

1. Comparing the Three Loop Types

DIN 66261 provides three loop blocks depending on when the condition is evaluated and whether the number of iterations is known in advance:

Loop TypeCheck TimingMin RunsBest Used For
While Loop (head-controlled)Before each iteration0Unknown count (e.g., search until found)
Do-While Loop (tail-controlled)After each iteration1Input validation (must run at least once)
For Loop (counting)Counter-controlled0 or NKnown iteration count or array traversal

2. Avoiding Infinite Loops

Always ensure that at least one variable checked in the loop condition is updated inside the loop body, otherwise the algorithm will never terminate.

Live Example (DIN 66261)

Rendered directly in DIN 66261 — click to open and edit in the workspace.

fakultaetBerechnen(n)ergebnis = 1ergebnis = ergebnis * ii = 1 bis n, Schrittweite 1Ausgabe: ergebnis

More Articles