Conditional Statements
Conditional statements let your program choose a path.
If something is true, do one thing. If not, do another.
Think of a fork in the road with two signs.
Why choices matter
If style choices
Switch style choices
What comes next
Programs that choose
Without conditions, code always does the same steps.
With conditions, code can react to ages, scores, and clicks.
Questions become booleans
A condition is usually a true or false test.
Comparisons and logical operators build those tests.
If and else
if handles the yes path.
else handles the no path.
You will practice this in the next lesson.
Many branches
Sometimes you have more than two options.
else if chains help. switch helps too.
Keep tests simple
One clear question per condition is easier to read.
Name boolean flags in plain words when you can.
Tip: Say your condition out loud. If you cannot explain it in one short sentence, simplify it.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.