Visual walkthrough — Control flow — if - else, switch, while, do-while, for, break, continue, goto
Step 0 — The four jobs every loop must do
PICTURE. Four coloured tiles, in the order the loop uses them. Keep these four colours in your head — every later figure re-uses them.

Step 1 — Trace the while version by hand
WHAT. We take a concrete while loop and walk the CPU through it.
int i = 0; // A
while (i < 3) { // B
printf("%d ", i); // S
i++; // C
}WHY this loop. It is the smallest loop that repeats more than once, so every job runs several times — perfect for watching the order of jobs.
PICTURE. Each row is one moment in time. Follow the arrows: A fires once at the top, then we spiral B → S → C → B → S → C … until B finally answers "no" and we exit on the right.

Step 2 — Trace the for version by hand
WHAT. Now the exact same behaviour, written as a for.
for (int i = 0; i < 3; i++) { // A ; B ; C all in the header
printf("%d ", i); // S in the body
}WHY. We want to see the same order of jobs emerge, even though the jobs are now crammed into one header line separated by semicolons: for (A; B; C) { S }.
PICTURE. The header packs A, B, C side by side, but the CPU still un-packs them into the very same spiral as Step 1. The arrows are drawn identically on purpose — compare this figure to the last one, tile by tile.

The order the CPU actually uses is:
This is identical to the while order in Step 1. That side-by-side sameness is the proof.
Step 3 — Lay them side by side (the equivalence appears)
WHAT. Put both traces next to each other and connect equal moments with lines.
WHY. Two programs are "the same" when, on the same input, they produce the same outputs and the same final state at every step. If every arrow matches, the programs are equivalent.
PICTURE. Left column = while, right column = for. Every horizontal grey link joins two moments that do the exact same thing. Not one link is missing — that visual completeness is the whole argument.

Step 4 — Edge case: the condition is false from the start
WHAT. Change the starting value so B is false immediately.
for (int i = 5; i < 3; i++) printf("%d ", i); // prints nothing
int j = 5; while (j < 3) { printf("%d ", j); j++; } // prints nothingWHY it matters. A reader must never be surprised. The rule "B is checked first" has a consequence: if the gate is shut on arrival, the body runs zero times. Both forms agree — because in both, A runs, then B is asked and answers "no", so we jump straight to exit.
PICTURE. A fires (i becomes 5), the very first B (5 < 3) answers no, and the red exit arrow skips the body entirely. This is precisely where do-while would differ — do-while runs the body once before asking, so it would print 5. That contrast is drawn on the right.

Step 5 — Degenerate case: no condition at all
WHAT. In C, any of A, B, C in a for header may be left blank. A blank B is treated as permanently true.
for (;;) { /* body */ } // forever, unless a break inside stops it
while (1) { /* body */ } // the same thingWHY. We must cover the empty inputs so nothing is left mysterious. An empty condition slot is not an error and is not false — the compiler substitutes "true", giving the classic infinite loop. The escape hatch is a break inside the body (from the parent note), which is why for(;;) is a common idiom.
PICTURE. The gate B is missing, so the arrow loops back forever; the only way out is a break arrow leaping out the side.

Step 6 — The crucial difference: where continue lands
WHAT. The equivalence in Step 3 is almost perfect — but continue exposes a seam.
WHY this deserves its own step. The parent note warned: continue in a for loop still runs the update C, but a careless hand-translation to while can skip C and hang. We now see why.
// for: continue jumps to C (the i++), so it stays safe
for (int i = 0; i < 5; i++) { if (i == 2) continue; printf("%d ", i); }
// naive while: continue jumps BEFORE i++ → i stuck at 2 forever!
int i = 0; while (i < 5) { if (i == 2) continue; printf("%d ", i); i++; }PICTURE. In the for case, the continue arrow lands on the C tile (update), then goes to B — progress is preserved. In the naive while, the continue arrow lands back on B, jumping over the update tile — i never changes, infinite loop.

The one-picture summary
Everything above compressed: the four tiles A/B/S/C, the single spiral they run in, the three special cases branching off (zero-times, forever, continue-seam).

Recall Feynman retelling — say it like you're 12
A loop is a little machine with four jobs, and it always does them in the same rhythm. First it sets things up once (that's A — "put 0 in the box i"). Then it asks a yes/no question (B — "is i still under 3?"). If yes, it does the work (S — "print i") and gives itself a nudge (C — "add 1 to i"), and loops back to ask again. If no, it walks out the door.
A for loop just packs the setup, the question, and the nudge onto one line, separated by semicolons — but the machine still un-packs them into the exact same rhythm. That's why for(A; B; C){S} and A; while(B){S; C;} are twins.
Three things to remember: (1) because the question comes first, the work can run zero times if the answer starts as "no". (2) If you leave the question blank, C pretends it's always "yes" — that's a forever-loop, and only a break gets you out. (3) continue in a for still runs the nudge C; if you copy a for into a while by hand and forget that, your i freezes and the loop never ends.
Active recall
Recall
In for(A;B;C){S}, how many times does A run? ::: Exactly once, before the first check of B.
If B is false on the very first check, how many times does S run? ::: Zero times (the gate is checked before the body).
What is for(;;) equivalent to and why? ::: while(1) — an empty condition is treated as permanently true, an infinite loop escaped only by break.
In a for loop, does continue skip the update C? ::: No — continue jumps to C, so the update still runs.
Why can a naive for→while translation with continue hang forever? ::: The continue jumps back to B before the manually-placed C, so the counter never updates.
State the equivalence between for and while. ::: for(A;B;C){S} ≡ A; while(B){ S; C; }.