if and else
Every program so far has run straight through, top to bottom. Conditionals let it choose.
An if statement takes a Boolean, everything you built in Module 6, and runs a block of code only when it's true. else handles every other case.
✦ The condition must produce a Boolean
Everything inside if(...) resolves to true or false before the branch is chosen. age >= 18 becomes True, then the if acts on it. This is why Module 6 came first: conditionals are just Booleans with consequences.
Mark this lesson complete
Signed in, your progress follows you to every device.