🧩Conditional Statement
Also known as If Statement, If Else, Conditional
An if runs code only when a test is true. Else runs when it is not.
Think of it like
Think of it like a fork in a path. If it rains you take the left path, else you take the right.
Example
A weather app checks if temp > 25. On a 30 degree day in Madrid it says shorts; on a cold day it says bring a coat.
Why it matters
Ifs are how a program makes choices. Every rule like you must be 13 to join is an if.
Definition
Example code
python
temp = 30
if temp > 25:
print("Shorts today")
else:
print("Bring a coat")
# prints: Shorts todayCommon mistake
Key takeaways
- 1Test first. The code inside runs only on true.
- 2Else catches the rest. It runs when the test is false.
- 3First match wins. In a chain, later tests are skipped.