Test MDX File V8
C++ Flow Lab
Section titled “C++ Flow Lab”Flow Lab…
C++ Control Flow Lab
See how switch, break, and continue redirect program flow.
int x = 5;switch (x) { case 1: cout << "test1"; case 5: cout << "test5"; default: cout << "none";}Without break, execution falls through from one matched case into every case below it — including default. Try x = 1 to see it cascade through every branch. This is occasionally useful, but almost always a bug.
C++ Loop Lab
Section titled “C++ Loop Lab”Loop Lab…
C++ Loop Lab
Pick a loop type and watch the program counter walk it — see exactly where each loop checks, steps, and jumps back.
int arr[] = {10, 20, 30, 40, 50};int n = 5; for (int i = 0; i < n; i++) { cout << arr[i] << " ";}All four loops produce the same output for this array, but their structure differs. for packs init, condition, and increment into one header. while separates them — init before the loop, increment inside the body. do-while tests the condition after the body, so the body always runs at least once — even if the condition starts false. range-based for (C++11) hides the counter, condition, and increment entirely — the compiler generates them so you can just say "for each element, do this".
© 2026 Derek Molloy, Dublin City University. All rights reserved.