All modules

Beginner -- Module 02

Control Statements

if/else, switch, while, do-while, and for -- plus the break/continue traps that catch almost everyone once. Includes a section on why C has no boolean type (until C23).

Video lesson

Downloadable notes

Plain-text lecture notes for Control Statements.

Download notes (.txt)

Practice problems

FizzBuzz, strictly

Print 1..30, replacing multiples of 3 with "Fizz", 5 with "Buzz", both with "FizzBuzz".

Warm-up

Menu-driven calculator

Use a switch on a char operator (+, -, *, /) to compute a result from two doubles, guarding divide-by-zero.

Core

Collatz step counter

For a given n, count how many steps the Collatz sequence takes to reach 1 using a do-while loop.

Stretch
Try these in the playground →

Module quiz

1. What does `continue` do inside a for loop?

2. A switch statement without a break in a case will:

3. In C, which value is considered false in a condition?

4. A do-while loop guarantees the body executes: