Skip to content
UPEEC

Control Flow in C

Decisions, loops and jumps — how a C program chooses what to run next.

Beginner
Comments 0

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

Beginner♥ 0🔖 0💬 0

if-else

Chooses between two paths.

Beginner♥ 0🔖 0💬 0

else-if Ladder

Tests several conditions in order; the first true one wins.

Beginner♥ 0🔖 0💬 0

for Loop

A counted loop: initialise; test; update.

Beginner♥ 0🔖 0💬 0

while Loop

Repeats while a condition is true, testing before each iteration.

Beginner♥ 0🔖 0💬 0

do-while Loop

Runs the body once, then repeats while the condition is true.

Beginner♥ 0🔖 0💬 0

break

Exits the innermost loop or switch immediately.

Beginner♥ 0🔖 0💬 0

continue

Skips to the next iteration of the innermost loop.

Beginner♥ 0🔖 0💬 0

goto

Jumps to a label in the same function.

Easy♥ 0🔖 0💬 0

Nested Loops

A loop inside another — for 2-D arrays, matrices and combinations.

Beginner♥ 0🔖 0💬 0

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.