Lesson 1 of 4 · 8 minutes
If this, then that
So far, every line ran every time. An if statement runs a block only when a condition is true.
The condition goes inside round brackets. The code inside curly brackets is the block. If the condition is false, the block is skipped. Nothing prints. The program continues.
Think of a fork in a path. Take one branch if the sign's condition is true. Otherwise, walk past it.
A true condition takes the branch. A false one walks past.
Loading the editor…
Change age to 15. Nothing prints, because the block is skipped.
Quick check
You can now make code run only when a condition is true.