Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Test MDX File V8

Flow Lab…

C++ Control Flow Lab

See how switch, break, and continue redirect program flow.

Input value
matches case 5
int x = 5;
switch (x) {
case 1: cout << "test1";
case 5: cout << "test5";
default: cout << "none";
}
Speed
case matchcase bodybreak
Trace
Press Start or Step to begin…
Output
(nothing printed yet)

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.

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] << " ";
}
Speed
initconditionincrementbody
Trace
Press Start or Step to begin…
Output
(nothing printed yet)

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".