Control Statements

Lesson 3 of 20

Teach your programs to choose: steer execution through if-else ladders and switch cases without a single wrong turn.

The big picture

Choices, choices

Programs get smart when they choose. if/else tests conditions; switch matches one value against fixed cases.

if / else if / else

Conditions are tested top to bottom — the first true branch runs and the rest are skipped.

switch

One value, many cases: a cleaner ladder when you are matching fixed options like menu choices.

break stops it

Without break, a matching case falls through into the next one — usually a bug.

default catches all

The case that runs when nothing else matched — a safety net for surprise values.