Control Flow in C
Decisions, loops and jumps — how a C program chooses what to run next.
This is an overview — pick a sub-topic below.
Sub-topics (12)
if Statement
Runs a block only when a condition is non-zero (true).
if-else
Chooses between two paths.
else-if Ladder
Tests several conditions in order; the first true one wins.
switch Statement
Selects a case by an integer value.
for Loop
A counted loop: initialise; test; update.
while Loop
Repeats while a condition is true, testing before each iteration.
do-while Loop
Runs the body once, then repeats while the condition is true.
break
Exits the innermost loop or switch immediately.
continue
Skips to the next iteration of the innermost loop.
goto
Jumps to a label in the same function.
Nested Loops
A loop inside another — for 2-D arrays, matrices and combinations.
Conditional Operator
`cond ? a : b` — an if-else that produces a value.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.