Concept

What is if/else branching?

An if/else statement checks a condition and runs exactly one of its paths — never both, never neither. Below is a real widget from epochai's own curriculum, not a flowchart diagram.

if age >= 18: is a question with a yes/no answer. If the condition is true, the code indented under if runs. If it's false, the code under else runs instead. One of those two blocks always runs — the other is skipped entirely, not just delayed.

The condition itself evaluates to a plain boolean, True or False, before the branch decision even happens. age >= 18 with age = 20 evaluates to True first; only then does the program decide which block to execute.

elif chains extend this to more than two options — Python checks each condition top to bottom and runs the first one that's true, skipping the rest. Nothing after the first match gets evaluated at all, which matters once conditions can overlap.

Watch it happen

The same interactive widget epochai's own lessons use — live, not a recording.

Playing automatically. Every epochai lesson also has an Explore mode where you drive it yourself.

This is one line out of 49 free lessons

Module 1 — Programming Fundamentals — covers variables, control flow, loops, functions, and debugging. Free, no card required.