Control flow
if, loops and switch as jumps — including fallthrough and off-by-one.
Before you start
By default a program runs top-to-bottom, one line after another. **Control flow** is how you make it do anything else: choose between paths (if), repeat something (while, for), or jump to one of many cases (switch).
Everything a program *does* — reacting to input, processing a list, retrying on failure — is control flow. The whole shape of a program is which lines run, in what order, how many times.
This lesson walks through each construct one step at a time so you can see exactly which branch is taken and how loop counters change on every iteration.
Stack
Control flow
75 is not ≥ 90. This branch is skipped — jump to else if.
Step 1 of 7. if tests conditions top to bottom. `score` is 75. The first test, `score >= 90`, is false — the body is skipped entirely. The machine jumps past it to the next `else if`. The conditions are evaluated in written order, and the first true one wins. Everything below it is skipped, even if it would also be true.
Step 01 / 07
if tests conditions top to bottom
score is 75. The first test, score >= 90, is false — the body is skipped entirely. The machine jumps past it to the next else if.
The conditions are evaluated in written order, and the first true one wins. Everything below it is skipped, even if it would also be true.
#include <stdio.h>int main(void) { int score = 75; // if / else if / else if (score >= 90) printf("A\n"); else if (score >= 70) printf("B\n"); // ← this branch else printf("C\n"); // while loop int i = 3; while (i > 0) { printf("%d ", i); i--; } // for loop — same thing, tidier for (int j = 0; j < 3; j++) { printf("%d ", j); } // switch + fallthrough trap switch (score / 10) { case 10: case 9: printf("A\n"); break; case 7: printf("B\n"); break; default: printf("other\n"); } return 0;}